Created
November 19, 2022 09:36
-
-
Save rassi0429/870c1605db74470a62f7ba45bff7fb20 to your computer and use it in GitHub Desktop.
Discord.py slash command Sample スラッシュコマンド サンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# discord ライブラリをインポート | |
import discord | |
# インテント(discordに何の情報が欲しいのかログインの時に伝える変数) | |
intents = discord.Intents.default() | |
intents.message_content = True | |
# Discordクライアントを準備 インテントを引数に渡してる | |
client = discord.Client(intents=intents) | |
# コマンドツリー | |
tree = discord.app_commands.CommandTree(client) | |
# ギルド変数(鯖IDを変数に入れておく) | |
guild_target = discord.Object(id=606109479003750440) | |
# ライブラリにイベントを登録 "on_ready" | |
# readyの時にDiscord側から実行される | |
@client.event | |
async def on_ready(): | |
print(f'We have logged in as {client.user}') | |
# コマンドツリーをシンク(同期する) | |
await tree.sync(guild=guild_target) | |
# コマンド登録 | |
@tree.command(name="test2", description="test description", guild=guild_target) | |
async def test(interaction: discord.Interaction): | |
# コマンドが呼ばれたときの処理 | |
print("test command received") | |
await interaction.response.send_message("Hi") | |
return | |
# DiscordにTokenでログインする | |
client.run('Your Token Here') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment