[英]Python discord bot, command not found
為什么我收到此錯誤: Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "Test" is not found
我看到了關於此的其他帖子,但問題是他們要么沒有令牌,要么底部沒有bot.run(TOKEN)
*編輯這是更新后的代碼,仍然出現相同的錯誤
import discord
from dotenv import load_dotenv
from discord.ext import commands
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
bot = commands.Bot(command_prefix='$', case_insensitive=True)
@bot.event
async def on_ready():
for guild in bot.guilds:
if guild.name == GUILD:
break
print(
f'{bot.user} is connected to the following guild:\n'
f'{guild.name}(id: {guild.id})'
)
@bot.command()
async def on_message(ctx, arg):
if ctx.author == bot.user:
return
if ctx.content.startswith('hello'):
await ctx.channel.send(arg)
bot.run(TOKEN)
bot.run(TOKEN)
你的代碼基本上是正確的。 您在聊天中編寫的命令中存在“拼寫”錯誤。 輸入命令時,您應該使用$test
而不是$Test
。 但是,您可以通過將case_insensitive
設置為True
來避免這些錯誤
在您的示例中,它看起來像這樣:
bot = commands.Bot(command_prefix='$', case_insensitive=True)
這應該工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.