実現したいこと
- Discord.pyをつかってコマンドを作成する(/コマンドではありません)
前提
pythonでdiscord.pyを使ってbotを作っています。コマンドを実装しようと思いましたが,コマンドが動作をしません。
python
1if message.content.startswith('起動確認'): 2 await message.channel.send(f'{client.user}は起動しています!') 3 return
このような,ただのメッセージに返信するようなことはできています。
発生している問題・エラーメッセージ
(何も帰ってきません)
該当のソースコード
python
1import os 2import discord 3from discord.ext import commands 4 5 6import time 7 8 9intents = discord.Intents.default() 10intents.message_content = True 11bot = commands.Bot(command_prefix='?', intents=intents) 12client = discord.Client(intents=discord.Intents.all()) 13 14 15@client.event 16async def on_ready(): 17 print('Logged in as') 18 print(client.user.name) 19 print(client.user.id) 20 print('------') 21 22#await message.channel.send(f"こんにちは、@{message.author}さん") 23 24@bot.command() 25async def test(ctx, *args): 26 arguments = ', '.join(args) 27 await ctx.send(f'{len(args)} arguments: {arguments}') 28async def boottest(ctx): 29 await message.add_reaction(emoji_heart) 30 await message.channel.send(f'{client.user}は起動しています!') 31 await message.channel.send('Logged in as') 32 await message.channel.send(client.user.name) 33 await message.channel.send(client.user.id) 34async def time(ctx): 35 res_time = time.strftime('%Y/%m/%d %H:%M:%S') 36 await message.channel.send(f"現在時刻は{res_time}です。") 37async def help(ctx): 38 await message.channel.send("現在次のコマンドが使用できます。`?test`,`?time`,`?boottest`,`?test`") 39 40 41 42 43client.run("ここにトークンが入ります")
試したこと
command_prefixの部分を変えたり,コマンドの名前を変えました。
上下は省きますが,以下のようなテキストに反応するものは動作しています。
python
1@client.event 2async def on_message(message): 3 if message.author == client.user: 4 return 5 6 if message.content.startswith('起動確認'): 7 await message.channel.send(f'{client.user}は起動しています!') 8 return
補足情報(FW/ツールのバージョンなど)
pythonはv3.10.9です。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。