はじめに
今回の記事の対象
- pythonの実行環境がすでに整っている
- vscordなどのeditorの準備がすでにできている
- pythonの基本的な書き方がわかっている
- discord botのアカウントの作成方法がわかっている
py-cordの入れ方
pip install py-cord
ターミナルに入力してください
基本的な使い方
prefixコマンドの実装方法
import discord
from discord.ext import commands
token = ""
bot = commands.Bot(
command_prefix="!",
intents=discord.Intents.all(),
help_command=None
)
@bot.command()
async def hello(ctx):
await ctx.respond(f"hello {ctx.author.mention}")
bor.run(token)
これでdiscord内で!helloと送信するとbotがhelloとコマンドを使った人へのメンションを送信してくれます
slashコマンドの実装方法
@bot.slashcommand()
async def hello(ctx):
await ctx.respond("hello")
これで実装できます
最後に
今回は基本的なpu-cordの使い方を説明しました
気が向けば他の実用的なコマンドの実装方法も上げていこうと思います
質問も気が付けば答えようと思います