一段代码循环,我不知道如何解决它
Piece of code looping, and i don't know how to solve it
在我的机器人中,它用于检测何时有人在错误的频道中输入命令。如果有人这样做,它会将他们引导到正确的频道,但机器人会检测到它自己的消息并循环。
我试过更改代码中的顺序并修改 if 语句
elif str(message.channel) != channel or str(message.channel) != admin_channel:
if message.content.find(str(commands)):
print(f"""User {message.author}, entered command {message.content} in the {message.channel} channel!""")
await message.channel.send(f"""Please enter commands in the #bot-commands channel!""")
我希望它能引导他们并停止,直到检测到另一条消息,但它检测到它自己的消息,因此,由于不断更新,它会循环
您所需要的只是代码中的某个地方,其中 client=bot,无论您在代码中为机器人命名什么,都会阻止它回复自己
@client.event
async def on_message(message):
#stops bot from replying to itself
if message.author == client.user:
return
在我的机器人中,它用于检测何时有人在错误的频道中输入命令。如果有人这样做,它会将他们引导到正确的频道,但机器人会检测到它自己的消息并循环。
我试过更改代码中的顺序并修改 if 语句
elif str(message.channel) != channel or str(message.channel) != admin_channel:
if message.content.find(str(commands)):
print(f"""User {message.author}, entered command {message.content} in the {message.channel} channel!""")
await message.channel.send(f"""Please enter commands in the #bot-commands channel!""")
我希望它能引导他们并停止,直到检测到另一条消息,但它检测到它自己的消息,因此,由于不断更新,它会循环
您所需要的只是代码中的某个地方,其中 client=bot,无论您在代码中为机器人命名什么,都会阻止它回复自己
@client.event
async def on_message(message):
#stops bot from replying to itself
if message.author == client.user:
return