Answer the question
In order to leave comments, you need to log in
DISCORD.BOT: Loops async def on_message. How to decide?
@Bot.event
async def on_message(message):
if message.author.id in white_list:
await message.channel.send('+')
if message.author.id not in white_list:
await message.channel.send('-')
Answer the question
In order to leave comments, you need to log in
I'm not strong at the moment in Python and discord.py, but I can say:
You have a "recursion" when the function calls itself.
This is due to the fact that your code also reacts to bot messages and issues a response.
Here is the fix:
@Bot.event
async def on_message(message):
if message.author.bot and message.author.id in white_list:
await message.channel.send('+')
else: await message.channel.send('-')
I know it's a long, long time. I will answer, maybe someone else needs it.
At the beginning of the function, you need to put the following condition:
It ignores bots and the function will not be recursively executed.
After all, on_message is also called when you send messages on behalf of your bot.
And also, if required, you can tighten the white list for bots:
if message.author.bot: return
if message.author.bot:
if not message.author.in in BOT_WHITE_LIST:
return
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question