ERROR discord.ext.commands.bot忽略命令中的异常None discord.ext.com.m



我当前在尝试调用此类内部的命令时遇到CommandNotFound错误。消息侦听器函数也没有响应。

ERROR    discord.ext.commands.bot Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "black" is not found

我似乎看不出我在这里做错了什么。。。

class MyCog(commands.Cog):

def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_message(self, message):
if message.content == "hello":
await message.channel.send("HI!")

@commands.command()
async def black(self, ctx):
await ctx.send("White!")

bot.add_cog(MyCog(bot))
bot.run(BOT_TOKEN)

当您添加一个齿轮时,您需要等待它。

await bot.add_cog(MyCog(bot))

要做到这一点,你需要改变你运行机器人的方式:

async def main():
async with bot:
await bot.add_cog(MyCog(bot))
await bot.start(BOT_TOKEN)
asyncio.run(main())

另一方面,我建议将cog移动到他们自己的python文件&目录它们对组织非常有用,但当保存在主机器人文件中时,大部分都会丢失。

相关内容

最新更新