我的代码在不协调的.py Cogs中运行了两次



我不确定我是否正确使用了cog,或者这是否会影响机器人运行两次命令,尽管我的所有命令都只在使用命令时运行两次。我相信问题来自于程序检查我是否运行了两次命令?

这种情况只发生在命令中,而不会发生在侦听器中。

我的电脑上只有一个运行机器人的例子,我仔细检查了一下。如果人们需要,我会给这个问题添加更多代码。

感觉我不断收到这样的错误:

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

以下是一些损坏的代码


class general_commands(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(aliases = ['c', 'clear'])
@commands.has_permissions(manage_messages = True)
async def clean(self, ctx, amount: int):
amount += 1
await ctx.channel.purge(limit = amount)
amount -= 1
msg = f"You've deleted {amount} messages"
await ctx.send(msg, delete_after = 5)

在下面的代码中,我调用了process_commands,这使得bot在每次发送消息时都会第二次运行这些命令。哇。

@commands.Cog.listener()
async def on_message(self, ctx):
if ctx.author.bot:
return
else:
for word in filtered_words:
if word in ctx.content:
await ctx.delete()
#random xp gain

最新更新