huss_a
huss_a

Reputation: 125

Reaction to messages not working (discord.py)

I wanted the bot to react to the message if it's sent by a certain author.

Code:

@bot.event
async def on_message(message):
    if message.author.id == '356268235697553409':
        await message.add_reaction('👍')
        await message.add_reaction('👎')
        await message.add_reaction('😐')

I tried this but it didn't work, it didn't even show any errors, what am I doing wrong? Thanks!

Upvotes: 0

Views: 75

Answers (3)

Shunya
Shunya

Reputation: 2429

First of all, as other users have already mentioned, you cannot compare an int to a string. The correct syntax would be:

if message.author.id == 356268235697553409:
    # Rest of your code here

Secondly, what you are doing is overriding the default provided on_message command. This forbids any commands from running, which might be the root cause of your issue. The correct way of using on_message would be adding the following like to the end of your on_message:

@bot.event
async def on_message(message):
    # Your code
    await bot.process_commands(message)

Alternatively, you an place your on_message logic into a listener (without the need of manually calling bot.process_commands(). This is done to allow multiple asynchronous actions in response to a message. Example:

@bot.listen('on_message')
async def whatever_you_want_to_call_it(message):
    # do stuff here

Upvotes: 0

Nurqm
Nurqm

Reputation: 4743

discord.Member.id returns you a int type value. That means that you cannot compare a str value to a discord.Member.id value. You just have to do:

if message.author.id == 356268235697553409:

Upvotes: 1

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15698

ID's are always integers, you're comparing an int to a string, to fix it:

if message.author.id == 356268235697553409:
    # ...

Upvotes: 0

Related Questions