Answer the question
In order to leave comments, you need to log in
It gives an error "object has no attribute", what should I do?
import discord
from discord import utils
import config
class MyClient(discord.Client):
async def on_ready(self):
print('Legged on as {0}!'.format(self.user))
async def on_raw_reaction_add(self, payload):
if payload.message_id == config.POST_ID:
channel = self.get_channel(payload.chanel_id)
message = await channel.fetch_message(payload.message_id)
member = utils.get(message.guild.members, id=payload.user_id)
try:
emoji = str(payload.emoji)
role = utils.get(message.guild.roles, id=config.ROLES[emoji])
if(len([i for i in member.roles if i.id not in config.EXCROLES]) <= config.MAX_ROLES_PER_USER):
await member.add_roles(role)
print('[SUCCESS] User {0.display_name} has been granted with role {1.name}'.format(member, role))
else:
await message.remove_reaction(payload.emoji, member)
print('[ERROR] Too many roles for user {0.display_name}'.format(member))
except KeyError as e:
print('[ERROR] KeyError, no role found for ' + emoji)
except Exception as e:
print(repr(e))
async def on_raw_reaction_remove(self, payload):
channel = self.get_channel(payload.chanel_id)
message = await channel.fetch_message(payload.message_id)
member = utils.get(message.guild.members, id=payload.user_id)
try:
emoji = str(payload.emoji)
role = utils.get(message.guild.roles, id=config.ROLES[emoji])
await member.remove_roles(role)
print('[SUCCESS] Role {1.name} has been remove for user {display_name}'.format(member, role))
except KeyError as e:
print('[ERROR] KeyError, not role found for ' + emoji)
except Exception as e:
print(repr(e))
client = MyClient()
client.run(config.TOKEN)
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "D:\pycharm\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "D:/pycharm/Lib/venv/bot.py", line 9, in on_raw_reaction_add
channel = self.get_channel(payload.chanel_id)
AttributeError: 'RawReactionActionEvent' object has no attribute 'chanel_id'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question