Advertisement
Guest User

role by reaction

a guest
Jan 29th, 2020
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. ----Discord input---
  2. >role faction; :horde: horde | :alli: alliance
  3.  
  4.  
  5. -----CODE------
  6. @bot.command()
  7. @commands.has_any_role('Admin', 'admin')
  8. async def role(ctx, user, reaction):
  9. getRole = ctx.message.content
  10. getRole = getRole.split(';')
  11. message = getRole[0].split(' ')
  12. del message[0]
  13. message = ' '.join(message)
  14. reactions = []
  15. description = []
  16. choices = getRole[1].split("|")
  17. try:
  18. for emoji in re.findall('<:(.+?)>', ctx.message.content):
  19. reactions.append(f'<:{emoji}>')
  20. except:
  21. print('no custom emojis')
  22. for choice in choices:
  23. description += '\n {}'.format(choice)
  24. embed = discord.Embed(title=message, description=''.join(description))
  25. react_message = await ctx.send(embed=embed)
  26. for react in reactions:
  27. await react_message.add_reaction(react)
  28. embed.set_footer(text='Request by: {}'.format(ctx.message.author))
  29. await react_message.edit(embed=embed)
  30. await ctx.message.delete()
  31. tmp = getRole[1].split(' ')
  32. print(tmp)
  33. roleList = []
  34. removeList = ['', '<', '|']
  35. for element in tmp:
  36. if element not in removeList:
  37. if element.isalpha():
  38. roleList.append(element)
  39. print('roleList: ', roleList)
  40. for user in reaction.user():
  41. print(user)
  42. role = discord.utils.get(user.server.roles, name='role name here --> roleList[x].name')
  43. await bot.add_roles(user, role)
  44.  
  45.  
  46.  
  47.  
  48. ---terminal output-----
  49.  
  50. C:\Users\mathi\Dropbox\Projets\Python_discord_bot\Bots>py PyBots.py
  51. Logged in as
  52. Name : PyBotWiP
  53. ID : 660122303916670988
  54. -------------------------
  55. ['', '<:horde:671358987719016529>', 'horde', '|', '<:alli:671358977463943201>', 'alliance']
  56. roleList: ['horde', 'alliance']
  57. Ignoring exception in command role:
  58. Traceback (most recent call last):
  59. File "C:\Users\mathi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 79, in wrapped
  60. ret = await coro(*args, **kwargs)
  61. File "PyBots.py", line 174, in role
  62. for user in reaction.user():
  63. AttributeError: 'str' object has no attribute 'user'
  64.  
  65. The above exception was the direct cause of the following exception:
  66.  
  67. Traceback (most recent call last):
  68. File "C:\Users\mathi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 863, in invoke
  69. await ctx.command.invoke(ctx)
  70. File "C:\Users\mathi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 728, in invoke
  71. await injected(*ctx.args, **ctx.kwargs)
  72. File "C:\Users\mathi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 88, in wrapped
  73. raise CommandInvokeError(exc) from exc
  74. 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