Discord bot 비망록 ①봇 작성편
소개
Discord bot를 만든 비망록
어떤 상황에서 Discord bot를 만들고 싶었기 때문에, bot 작성으로부터 다양한 액션의 비망록
slackbot 이외에도 손을 내고 싶었다
물품 쓰기는 다음과 같습니다
Discord란?
Discord(디스코드)란, ~~~ 음성 통화·VoIP 프리 소프트웨어이다.
(Wikipedia에서)
지금까지 Slack처럼 사용한 적이 여러 번있었습니다.
Slack에 봇이 있으니까 Discord도…
Discord bot를 만드는 방법
디스코드 개발자 에서 작성
응용 프로그램 페이지에서 새 응용 프로그램을 클릭

봇 이름을 듣기 때문에 좋아하는 봇 이름을 붙인다.
Bot 페이지를 열고 Add Bot 버튼을 클릭합니다.
Yes, do it!도 클릭

생성된 봇이 표시됨
아이콘과 이름도 변경 가능
TOKEN 이름을 복사하십시오.

OAuth2를 다음과 같이 설정
(일단 TEXT계는 모두 ON으로 해 보았다)


OAuth2 설정 화면의 URL에 접속하면 어디의 Discord 룸에 Bot를 초대할지 묻는다
정체가 끝나면 멋지게 봇이 방에 들어온다

모듈, 디렉토리 구조 등
모듈
모듈은 다음과 같습니다
필요한 경우 설치하십시오.
pip install discord # discordを使用する際に必要
디렉토리 구조
디렉토리 구조는 다음과 같습니다.
- dis_python
- img
- good.png
-dis_test.py
여러 가지를 만들어 보았습니다.
공식 씨
ぢs 아이 rd. py 씨 여러가지가 쓰여져 있습니다.
해보고 싶은 것을 철저히 조사하면 재미 있습니다.
프로그램
dis_test.pyimport discord
TOKEN = "BotのTOKENを張り付ける"
client = discord.Client()
GOOD_IMG = "./img/good.PNG"
### イベントハンドラ一覧 #################################################
# async def の後を変えるだけで実行されるイベンドが変わる
# メッセージ受信時に実行: on_message(message)
# Bot起動時に実行: on_ready(message)
# リアクション追加時に実行: on_reaction_add(reaction, user)
# 新規メンバー参加時に実行: on_member_join(member)
# ボイスチャンネル出入に実行: on_voice_state_update(member, before, after)
###################################################################
# bot起動時処理
@client.event
async def on_ready():
channel = client.get_channel(チャンネルIDを張り付ける)
await channel.send("やぁ!元気かい?")
# message を受け取ったとき
@client.event
async def on_message(message):
# 送り手がボットの場合、無視
if message.author.bot:
return
if message.content.startswith("こんにちは"):
await message.channel.send("こんにちは!")
if len(message.attachments) > 0:
await message.channel.send("何かファイルを送ったね???")
@client.event
async def on_reaction_add(reaction, user):
await reaction.message.channel.send('{}を押したね??'.format(reaction.emoji), file=discord.File(GOOD_IMG))
client.run(TOKEN)
세세한 설명은 다음 번에 정리하겠습니다.
조금 해설
TOKEN과 채널 ID는 자신이 사용하는 것을 사용하십시오.
채널 ID는 URL 맨 뒤의 '숫자 2'입니다.
://discordapp.com/channels/숫자들1/숫자들2
이벤트 핸들러 일람에는 사용할 것 같은 것을 정리하고 있습니다
특히 on_message ()는 잘 사용합니다.
출력 결과
명령줄

bot와의 연극


우선 대략 정리해 보았다
문서에 관해서는 내용이 짙기 때문에 다음에 돌리고 싶습니다.
특히 on_message에서의 파일 조작 등이 의외로 번거로웠기 때문에 그 근처의 비망록을 (˘ω˘)
Reference
이 문제에 관하여(Discord bot 비망록 ①봇 작성편), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/str32/items/39283355e71240113e09
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
디스코드 개발자 에서 작성
응용 프로그램 페이지에서 새 응용 프로그램을 클릭

봇 이름을 듣기 때문에 좋아하는 봇 이름을 붙인다.
Bot 페이지를 열고 Add Bot 버튼을 클릭합니다.
Yes, do it!도 클릭

생성된 봇이 표시됨
아이콘과 이름도 변경 가능
TOKEN 이름을 복사하십시오.

OAuth2를 다음과 같이 설정
(일단 TEXT계는 모두 ON으로 해 보았다)


OAuth2 설정 화면의 URL에 접속하면 어디의 Discord 룸에 Bot를 초대할지 묻는다
정체가 끝나면 멋지게 봇이 방에 들어온다

모듈, 디렉토리 구조 등
모듈
모듈은 다음과 같습니다
필요한 경우 설치하십시오.
pip install discord # discordを使用する際に必要
디렉토리 구조
디렉토리 구조는 다음과 같습니다.
- dis_python
- img
- good.png
-dis_test.py
여러 가지를 만들어 보았습니다.
공식 씨
ぢs 아이 rd. py 씨 여러가지가 쓰여져 있습니다.
해보고 싶은 것을 철저히 조사하면 재미 있습니다.
프로그램
dis_test.pyimport discord
TOKEN = "BotのTOKENを張り付ける"
client = discord.Client()
GOOD_IMG = "./img/good.PNG"
### イベントハンドラ一覧 #################################################
# async def の後を変えるだけで実行されるイベンドが変わる
# メッセージ受信時に実行: on_message(message)
# Bot起動時に実行: on_ready(message)
# リアクション追加時に実行: on_reaction_add(reaction, user)
# 新規メンバー参加時に実行: on_member_join(member)
# ボイスチャンネル出入に実行: on_voice_state_update(member, before, after)
###################################################################
# bot起動時処理
@client.event
async def on_ready():
channel = client.get_channel(チャンネルIDを張り付ける)
await channel.send("やぁ!元気かい?")
# message を受け取ったとき
@client.event
async def on_message(message):
# 送り手がボットの場合、無視
if message.author.bot:
return
if message.content.startswith("こんにちは"):
await message.channel.send("こんにちは!")
if len(message.attachments) > 0:
await message.channel.send("何かファイルを送ったね???")
@client.event
async def on_reaction_add(reaction, user):
await reaction.message.channel.send('{}を押したね??'.format(reaction.emoji), file=discord.File(GOOD_IMG))
client.run(TOKEN)
세세한 설명은 다음 번에 정리하겠습니다.
조금 해설
TOKEN과 채널 ID는 자신이 사용하는 것을 사용하십시오.
채널 ID는 URL 맨 뒤의 '숫자 2'입니다.
://discordapp.com/channels/숫자들1/숫자들2
이벤트 핸들러 일람에는 사용할 것 같은 것을 정리하고 있습니다
특히 on_message ()는 잘 사용합니다.
출력 결과
명령줄

bot와의 연극


우선 대략 정리해 보았다
문서에 관해서는 내용이 짙기 때문에 다음에 돌리고 싶습니다.
특히 on_message에서의 파일 조작 등이 의외로 번거로웠기 때문에 그 근처의 비망록을 (˘ω˘)
Reference
이 문제에 관하여(Discord bot 비망록 ①봇 작성편), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/str32/items/39283355e71240113e09
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
pip install discord # discordを使用する際に必要
- dis_python
- img
- good.png
-dis_test.py
공식 씨
ぢs 아이 rd. py 씨 여러가지가 쓰여져 있습니다.
해보고 싶은 것을 철저히 조사하면 재미 있습니다.
프로그램
dis_test.py
import discord
TOKEN = "BotのTOKENを張り付ける"
client = discord.Client()
GOOD_IMG = "./img/good.PNG"
### イベントハンドラ一覧 #################################################
# async def の後を変えるだけで実行されるイベンドが変わる
# メッセージ受信時に実行: on_message(message)
# Bot起動時に実行: on_ready(message)
# リアクション追加時に実行: on_reaction_add(reaction, user)
# 新規メンバー参加時に実行: on_member_join(member)
# ボイスチャンネル出入に実行: on_voice_state_update(member, before, after)
###################################################################
# bot起動時処理
@client.event
async def on_ready():
channel = client.get_channel(チャンネルIDを張り付ける)
await channel.send("やぁ!元気かい?")
# message を受け取ったとき
@client.event
async def on_message(message):
# 送り手がボットの場合、無視
if message.author.bot:
return
if message.content.startswith("こんにちは"):
await message.channel.send("こんにちは!")
if len(message.attachments) > 0:
await message.channel.send("何かファイルを送ったね???")
@client.event
async def on_reaction_add(reaction, user):
await reaction.message.channel.send('{}を押したね??'.format(reaction.emoji), file=discord.File(GOOD_IMG))
client.run(TOKEN)
세세한 설명은 다음 번에 정리하겠습니다.
조금 해설
TOKEN과 채널 ID는 자신이 사용하는 것을 사용하십시오.
채널 ID는 URL 맨 뒤의 '숫자 2'입니다.
://discordapp.com/channels/숫자들1/숫자들2
이벤트 핸들러 일람에는 사용할 것 같은 것을 정리하고 있습니다
특히 on_message ()는 잘 사용합니다.
출력 결과
명령줄

bot와의 연극


우선 대략 정리해 보았다
문서에 관해서는 내용이 짙기 때문에 다음에 돌리고 싶습니다.
특히 on_message에서의 파일 조작 등이 의외로 번거로웠기 때문에 그 근처의 비망록을 (˘ω˘)
Reference
이 문제에 관하여(Discord bot 비망록 ①봇 작성편), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/str32/items/39283355e71240113e09텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)