Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----Discord input---
- >role faction; :horde: horde | :alli: alliance
- -----CODE------
- @bot.command()
- @commands.has_any_role('Admin', 'admin')
- async def role(ctx, user, reaction):
- getRole = ctx.message.content
- getRole = getRole.split(';')
- message = getRole[0].split(' ')
- del message[0]
- message = ' '.join(message)
- reactions = []
- description = []
- choices = getRole[1].split("|")
- try:
- for emoji in re.findall('<:(.+?)>', ctx.message.content):
- reactions.append(f'<:{emoji}>')
- except:
- print('no custom emojis')
- for choice in choices:
- description += '\n {}'.format(choice)
- embed = discord.Embed(title=message, description=''.join(description))
- react_message = await ctx.send(embed=embed)
- for react in reactions:
- await react_message.add_reaction(react)
- embed.set_footer(text='Request by: {}'.format(ctx.message.author))
- await react_message.edit(embed=embed)
- await ctx.message.delete()
- tmp = getRole[1].split(' ')
- print(tmp)
- roleList = []
- removeList = ['', '<', '|']
- for element in tmp:
- if element not in removeList:
- if element.isalpha():
- roleList.append(element)
- print('roleList: ', roleList)
- for user in reaction.user():
- print(user)
- role = discord.utils.get(user.server.roles, name='role name here --> roleList[x].name')
- await bot.add_roles(user, role)
- ---terminal output-----
- C:\Users\mathi\Dropbox\Projets\Python_discord_bot\Bots>py PyBots.py
- Logged in as
- Name : PyBotWiP
- ID : 660122303916670988
- -------------------------
- ['', '<:horde:671358987719016529>', 'horde', '|', '<:alli:671358977463943201>', 'alliance']
- roleList: ['horde', 'alliance']
- Ignoring exception in command role:
- Traceback (most recent call last):
- File "C:\Users\mathi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 79, in wrapped
- ret = await coro(*args, **kwargs)
- File "PyBots.py", line 174, in role
- for user in reaction.user():
- AttributeError: 'str' object has no attribute 'user'
- The above exception was the direct cause of the following exception:
- Traceback (most recent call last):
- File "C:\Users\mathi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 863, in invoke
- await ctx.command.invoke(ctx)
- File "C:\Users\mathi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 728, in invoke
- await injected(*ctx.args, **ctx.kwargs)
- File "C:\Users\mathi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 88, in wrapped
- raise CommandInvokeError(exc) from exc
- discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'user'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement