Reputation: 9
There is a problem with this program. I'm trying to make it so when someone types 'hi' in Discord, two bots respond. The problem is that the bots keep saying hi to the other one. Here is the code:
msg = message.content# Makes sure that the author of the message isn't itself
if message.author == client.user:
return
if message.author.id != '818469783891607562':
if any(word in msg for word in common_Greetings_List):
time.sleep(2)
await message.channel.send("Hey!")```
Upvotes: 0
Views: 2026
Reputation: 3497
The User
object has a bot
attribute that you can check. This way your bot can ignore all bot messages.
if message.author.bot:
return
Upvotes: 1
Reputation: 1331
You are preventing the bots from reacting to their own messages but you are not stating anything that prevents them from reacting to each other's message.
You can easily fix this with an additional condition in your first if block:
if message.author.id in [client.user.id, other_bot_id_here]:
return
(I'm assuming that "Hey!" belongs to the common_Greetings_List
).
If you want your bots to keep reacting to each other's message except for the greetings, you can change the bot's reply in some string that doesn't belong to the greetings list.
Upvotes: 1