20210325 AStudy+ https://askul.connpass.com/event/204742/ speaker:みわすけ
DiscordBot はじめの⼀歩アスクル株式会社三輪亮介
View Slide
⾃⼰紹介• ⾃分について⾊々わかっていないためサイズ違いの靴や服が余っている• 社会⼈になって太った• 業務では、AWSの構築などインフラ関連のことを⾏なっている1
⽬次1. Discordの紹介2. やってみる3. Botの例2
Discordって︖• ビデオ、⾳声通話ソフト• 1つのサーバーに複数の通話部屋、チャット部屋を作ることができる3
4
DiscordのBotって︖• ユーザーの⼊⼒に⾃動応答させられる• ユーザーができることはだいたいできる• 複数⾔語対応(https://discordpy.readthedocs.io/ja/latest/api.html)5
6やってみる
サンプルimport discordimport osimport setToken# 環境変数を使うべき。今回は外部ファイルを参照# token = os.environ['DISCORD_TOKEN’]TOKEN = setToken.tokenclient = discord.Client()# 起動時@client.eventasync def on_ready():print("AStudy discordBot")# チャットイベント@client.eventasync def on_message(message):# メッセージ送信者がBotだった場合は無視するif message.author.bot:return# /test に対してhelloを返答if message.content == '/test':await message.channel.send('hello')# bot起動client.run(TOKEN)7