0
votes

Im Trying to make a discord bot which sends an embed message with a reaction, and if a user reacts to that message he/she would get a role. This is for the Rules of the Server.

The Problem is, the Embed message gets sent but there is no reaction. If I manually react to it, and get someone else to react too he/she will get no role. (The embed message is the only message in that channel). I also get no Errors in the console.

The 'channel_id_will_be_here' is always replaced with the correct channel Id.

Thank you.

import discord
from discord.ext import commands

client = discord.Client()

@client.event
async def on_ready():
    Channel = client.get_channel('channel_id_will_be_here')
    print("Ready as always chief")

@client.event
async def on_message(message):
    if message.content.find("|rules12345654323") != -1:
        embedVar = discord.Embed(title="**Rules**", description="The Rules Everybody needs to follow.", colour=discord.Colour.from_rgb(236, 62, 17))
        embedVar.add_field(name="Rule 1", value="Be nice etc", inline=False)
       
        await message.channel.send(embed=embedVar)

async def on_reaction_add(reaction, user):
    Channel = client.get_channel('channel_id_will_be_here')
    if reaction.message.channel.id != Channel:
        return
    if reaction.emoji == ":white_check_mark:":
        Role = discord.utils.get(user.server.roles, name="Player")
        await client.add_roles(user, Role)
1

1 Answers

0
votes

In if reaction.message.channel.id != Channel you compare the id to the Channel object, not the Channel.id.

You don't need to use the object there, just the id (which you use to create the channel object in the first place) would be fine

if reaction.message.channel.id != channel_id_will_be_here:
    return

You could also use the message id like(So it'll only trigger when reacting to that exact message):

if reaction.message.id != rules_message_id_will_be_here:
    return

The way you do your check is pretty strange too, why check to make the function return if False? Why not just make it add the role when True?


async def on_reaction_add(reaction, user):
    if reaction.message.channel.id == channel_id_will_be_here and reaction.emoji == ":white_check_mark:":
        Role = discord.utils.get(user.server.roles, name="Player")
        await client.add_roles(user, Role)

You could even leave out the if reaction.emoji == ":white_check_mark:": part if it is the only message/emote reaction in that channel