Answer the question
In order to leave comments, you need to log in
My code doesn't work but doesn't throw a discord py error?
My bot should issue roles by reacting to emoji, but it doesn't work. However, no error is displayed in the console. Here is my code:
import discord
from discord.ext import commands
import json
client = commands.Bot(command_prefix = ".")
@client.event
async def on_raw_reaction_add(payload):
if payload.member.bot:
pass
else:
with open('reactrole.json') as react_file:
data = json.load(react_file)
for x in data:
if x['pubg_emoji'] == payload.emoji.name:
role = discord.utils.get(client.get_guild(payload.guild_id).roles, id=x['pubg_id'])
await payload.member.add_roles(role)
@client.command()
async def reactrole(ctx,emoji,role : discord.Role,*,message):
emb = discord.Embed(description = message)
msg = await ctx.channel.send(embed = emb)
await msg.add_reaction (emoji)
client.run("My token")
["pubg_emoji":":pubg:","pubg_id": 817371069547020308]
Answer the question
In order to leave comments, you need to log in
File ID:
["pubg_emoji":":pubg:","pubg_id": 817371069547020308]
for x in data:
if x['pubg_emoji'] == payload.emoji.name:
I tried to fix it but now the error is different:
line 13, in on_ready
await client.add_reaction(Moji, emoji='')
AttributeError: 'Bot' object has no attribute 'add_reaction'
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = ".",intents = discord.Intents.all())
@client.event
async def on_ready():
print(discord.__version__)
Channel = client.get_channel(815949348948934716)
Text= "Выбери свою роль"
Moji = await Channel.send(Text)
await client.add_reaction(Moji, emoji='')
@client.event
async def on_reaction_add(reaction, user):
Channel = client.get_channel(815949348948934716)
if reaction.message.channel.id != Channel:
return
if reaction.emoji == "":
Role = discord.utils.get(user.server.roles, name="PUBG")
await client.add_roles(user, Role)
client.run("My token")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question