「Discord」の版間の差分
		
		
		
		
		
		ナビゲーションに移動
		検索に移動
		
				
		
		
	
| 編集の要約なし | 編集の要約なし | ||
| 37行目: | 37行目: | ||
| * https://discordpy.readthedocs.io/ja/latest/ext/tasks/index.html | * https://discordpy.readthedocs.io/ja/latest/ext/tasks/index.html | ||
| @tasks.loop() デコレータの処理を宣言して、on_ready()で開始する | |||
| @tasks.loop(minutes=30) とすれば30分おきに実行 | |||
| <syntaxhighlight> | |||
| jst = datetime.timezone(datetime.timedelta(hours=+9), 'JST') | |||
| times = [ | |||
|     datetime.time(hour=13, minute=00, tzinfo=jst) | |||
| ] | |||
| @tasks.loop(time=times) | |||
| </syntaxhighlight> | |||
| のようにすれば指定の時刻に実行される | |||
| == スラッシュコマンド == | == スラッシュコマンド == | ||
2025年3月6日 (木) 00:01時点における版
主にdiscord.pyについて書く
Discord bot の作成
- Applicationを作成する
- botアカウントを追加
- Privileged Gateway Intentsを設定する
- botをサーバーに招待する
messageに含まれる情報
- id
できること
リアクションをつける
async def on_message(message):
	await message.add_reaction('👍')
リプライ
async def on_message(message):
	await message.reply('リプライ')
ファイル送信
channel = client.get_channel(CHANNEL_ID)
await channel.send(file=discord.File("filename"))
定期実行
@tasks.loop() デコレータの処理を宣言して、on_ready()で開始する
@tasks.loop(minutes=30) とすれば30分おきに実行
jst = datetime.timezone(datetime.timedelta(hours=+9), 'JST')
times = [
    datetime.time(hour=13, minute=00, tzinfo=jst)
]
@tasks.loop(time=times)のようにすれば指定の時刻に実行される
スラッシュコマンド
このへんに書かれてます https://discordpy.readthedocs.io/ja/latest/interactions/api.html#discord.app_commands.Command
引数の入力補完には choices か autocomplete が使えそうだが、choices は25個までの制限がある模様