Hello everyone. I have an infinite loop in my discord bot, but I do not know how to solve it.
import discord
import asyncio
import strings_codes #minha classe de string e códigos
import auxiliary_functions #minha classe de funções auxiliares
client = discord.Client()
@client.event
async def on_ready():
await client.send_message(client.get_channel(strings_codes.test_channel_id), strings_codes.welcome_message)
@client.event
async def on_message(message):
lower_command = message.content.lower()
if lower_command.startswith('!'):
await client.send_message(message.channel, auxiliary_functions.switch_command(message))
else:
await client.send_message(message.channel, strings_codes.invalid_commands['wrong_prefix'])
client.run(strings_codes.token)
The on_ready()
method calls the send_message()
method with the greeting message and triggers the on_message()
method, which also has the send_message()
method in its scope, thus making the bot infinitely capturing the your own message. I've seen many people code and they did not have to put a condition to trigger the event that has the on_message()
method. How do I solve this? Thankful.