2
votes

But not worked for me..,

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
from discord import Game
import math, time
from discord.ext import commands
from discord.utils import get


 Client = discord.client
 client = commands.Bot(command_prefix = '!')
 Clientdiscord = discord.Client()


@client.event
 async def on_ready():

 Channel = client.get_channel('524415641310986252')
 Text= "testt!"
 Moji = await client.send_message(Channel, Text)
 await client.add_reaction(Moji, emoji='\U0001F3D3')

 client.loop.create_task(on_reaction_add())

@client.event
 async def on_reaction_add(reaction, user):
Channel = client.get_channel('524415641310986252')
if reaction.message.channel.id != Channel:
 return
if reaction.emoji == "\U0001F3D3":
  Role = discord.utils.get(user.server.roles, name="verified")
  await client.add_roles(user, Role)
  await client.add_roles(reaction.message.author, role)

client.run("My_Token")

Ignoring exception in on_ready Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) File "C:\Users\Administrator\Desktop\project_Bot_manage - - Copy - Copy.py", line 24, in on_ready client.loop.create_task(on_reaction_add()) TypeError: on_reaction_add() missing 2 required positional arguments: 'reaction' and 'user'

Please I need help , I'm still new here with discord.py

1
i tried this too, and not worked : stackoverflow.com/questions/52210855/… - Dev I.A
What is this line supposed to do client.loop.create_task(on_reaction_add())? You don't need that line - Patrick Haugh
@PatrickHaugh okey i removed that line, (no problem showed + not gaved me the role.) - Dev I.A
reaction.message.channel.id != Channel you should be comparing the two Channel objects, not a Channel object with a string. Try reaction.message.channel != Channel - Patrick Haugh
@PatrickHaugh it worked,thanks, can you post it as "answer the question", and please can you add a while i remove my reaction will remove my role, i tried if reaction.emoji == "\U0001F3D3": Role = discord.utils.get(user.server.roles, name="verified") await client.add_roles(user, Role) await client.add_roles(reaction.message.author, Role) else: await bot.remove_roles(reaction.message.author,Role) if Role in reaction.message.author.roles: await client.remove_roles(reaction.message.author,Role) else: await client.add_roles(reaction.message.author,Role) - Dev I.A

1 Answers

0
votes

You need an on_reaction_remove event to remove the role when the user removes their reaction:

msg = None
tennis = "\N{TABLE TENNIS PADDLE AND BALL}"

@client.event
async def on_ready():
    channel = client.get_channel('524415641310986252')
    global msg
    msg = await client.send_message(channel, "React to me!")
    await client.add_reaction(msg, tennis)

@client.event
async def on_reaction_add(reaction, user):
    if reaction.user == client.user:
        return
    if reaction.message == msg and reaction.emoji == tennis:
        verified = discord.utils.get(user.server.roles, name="verified")
        await client.add_roles(user, verified)

@client.event
async def on_reaction_remove(reaction, user):
    if reaction.message == msg and reaction.emoji == tennis:
        verified = discord.utils.get(user.server.roles, name="verified")
        await client.remove_roles(user, verified)