Discord py bot 不触发和忽略命令
Discord py bot not triggering and ignoring commands
我有这个机器人,它会在每次有人使用 on_message
事件发送消息时进行检查,并且出于某种原因,机器人似乎忽略了其他命令。
我在删除检查消息的功能后发现了这一点,命令工作得很好。
这里是 on_message
事件代码:
@client.event
async def on_message(message):
text = message.content
chann = message.channel.id
yes1 = False
yes = False
for ide in ids:
if message.author.id == ide:
yes1 = True
for strf in comms:
if text.startswith(strf):
yes = True
if (yes == False) and (yes1 == False) and (chann == 822089739502616576) and (message.author.id != 769302967803183124):
print(message.author.id)
msg = await message.channel.send('lahne kel el commands ye bhim')
await message.delete()
await asyncio.sleep(2)
print('deleting message')
await msg.delete()
if yes and (message.author.id != 769302967803183124) and (message.channel.id == 331562608467509249):
print(message.author.id)
msg = await message.channel.send('mech lahne tekteb el commands ye bhim')
await message.delete()
await asyncio.sleep(2)
print('deletingmessage')
await msg.delete()
if yes1 and (chann == 331562608467509249) and (message.author.id != 769302967803183124):
await message.delete()
不知道问题出在哪里
您需要将 await client.process_commands(message)
添加到 on_message 协程的末尾。
作为 docs 状态:
By default, this coroutine is called inside the on_message() event. If you choose to override the on_message() event, then you should invoke this coroutine as well.
我有这个机器人,它会在每次有人使用 on_message
事件发送消息时进行检查,并且出于某种原因,机器人似乎忽略了其他命令。
我在删除检查消息的功能后发现了这一点,命令工作得很好。
这里是 on_message
事件代码:
@client.event
async def on_message(message):
text = message.content
chann = message.channel.id
yes1 = False
yes = False
for ide in ids:
if message.author.id == ide:
yes1 = True
for strf in comms:
if text.startswith(strf):
yes = True
if (yes == False) and (yes1 == False) and (chann == 822089739502616576) and (message.author.id != 769302967803183124):
print(message.author.id)
msg = await message.channel.send('lahne kel el commands ye bhim')
await message.delete()
await asyncio.sleep(2)
print('deleting message')
await msg.delete()
if yes and (message.author.id != 769302967803183124) and (message.channel.id == 331562608467509249):
print(message.author.id)
msg = await message.channel.send('mech lahne tekteb el commands ye bhim')
await message.delete()
await asyncio.sleep(2)
print('deletingmessage')
await msg.delete()
if yes1 and (chann == 331562608467509249) and (message.author.id != 769302967803183124):
await message.delete()
不知道问题出在哪里
您需要将 await client.process_commands(message)
添加到 on_message 协程的末尾。
作为 docs 状态:
By default, this coroutine is called inside the on_message() event. If you choose to override the on_message() event, then you should invoke this coroutine as well.