问题
Not so long ago added in my discord bot chat-filter ,which delete messages which i dont want to see.But i have a problem with this.Before this new event my bot sends on the command $hello 1 message(hello,{me}),but with this chat filter he sends 2 or more questions(Number of posts = number of banned words).Can u heip me with this.
@Bot.event
async def on_message( message ):
filter = ['!leave', '!play','!skip']
for word in filter:
if word in message.content:
print('%s bad word' % (message.author.id))
await message.channel.purge(limit=1)
await message.author.send('Просьба писать команды для бота в #music')
await Bot.process_commands(message)
This is the chat filter code that the problem is. I think that because of this filter, all my code compiles three times
回答1:
Guessing this is a dup of this question
Since you have 2 on_message()
functions only the second one will be processed. You should remove one.
You issue with the multiple messages is because you are processing your await bot.process_commands(message)
command in your for
loop. Based on having 3 bad words you have 3 messages.
Try de-indenting your await bot.process_commands(message)
to be even with your for word in filter
.
来源:https://stackoverflow.com/questions/61562890/my-discord-py-bot-with-chat-filter-event-sends-2-or-more-messages-instead-of-1