Reputation: 3
my message is spamming, I only want to send it 1 time. how to fix?
@client.event async def on_message(message): if 'happy birthday' in message.content.lower(): await message.channel.send('Happy Birthday! ๐๐')
Upvotes: 0
Views: 347
Reputation: 310
You are creating an infinite loop, when the bot sends โHappy Birthday!โ
โhappy birthdayโ
is in the lowercase version of the message. So the bot reads happy birthday
and sends a message, Happy Birthday!
. Which the bot detects as a new message, the new message (when converted to lowercase) contains happy birthday
so the bot sends a message.
There are two ways to fix this, you can change the content of the message to not contain happy birthday
Or you could check if the message is sent from anyone but the bot using message.author
message docs page
Upvotes: 0
Reputation: 4743
Because it's an on_message
event and it detects also the bot's messages and bot is sending a message including happy birthday.
If you don't want it spamming, you can check if author is a bot account with message.author.bot
.
@client.event
async def on_message(message):
if message.author.bot:
return
if 'happy birthday' in message.content.lower():
await message.channel.send('Happy Birthday! ๐๐')
Upvotes: 1