discord.pyでスラッシュコマンド
#v2
Discord.pyのスラッシュコマンドの例
https://gist.github.com/Rapptz/c4324f17a80c94776832430007ad40e6#slash-commands-and-context-menu-commands
これちょっと古いかも
https://discordpy.readthedocs.io/ja/latest/api.html?highlight=application_id#client
application_idも必須?
https://discord.com/developers/applications/
上のGeneral Informationにある、APPLICATION ID
https://gyazo.com/fe6fd838a623deb4fd12c467c3214ab9
code:test.py
import discord
from discord import app_commands
TOKEN = 'TOKEN'
APPLICATION_ID = 'APPLICATION_ID'
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents, application_id=APPLICATION_ID)
tree = app_commands.CommandTree(client)
@tree.command(guild=discord.Object(id=myGuildId))
async def slash(interaction: discord.Interaction):
await interaction.response.send_message(f'hello world')
@client.event
async def on_ready():
await tree.sync()
client.run(TOKEN)
古い環境のため非推奨
discord.py v1で使ってみたい方は、別の開発者が作成したdiscord-py-interactionsを導入することで使うことができます
気合いがありすぎる人だけ
自分でスラッシュコマンドを実装することもできます