Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # config.py
- # ID of message with reaction roles
- reaction_message_id=816005108306935839
- # bot token
- token='hidden_token'
- roles={
- ":ice_cube:": "816004965688541224",
- ":loudspeaker:": "816004985720012801",
- ":bell:": "816005011896533017"
- }
- # bot.py
- import discord
- from discord import utils
- import config
- import sys
- print("Python version: {0}".format(sys.version))
- class MyClient(discord.Client):
- async def on_ready(self):
- print('Logged in as {0}'.format(self.user))
- pass
- async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent):
- if payload.message_id == config.reaction_message_id:
- channel = self.get_channel(payload.channel_id)
- message = await channel.fetch_message(payload.message_id)
- user = self.get_user(payload.user_id)
- print(user)
- try:
- emoji = config[payload.emoji]
- role = utils.get(message.guild.roles, id=config.roles[emoji])
- await user.add_roles(role)
- print('[SUCCESS] User {0.display_name} has been granted with role {1.name}'.format(user, role))
- 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.channel_id)
- message = await channel.fetch_message(payload.message_id)
- user = utils.get(message.guild.members, id=payload.user_id)
- print(user)
- try:
- emoji = str(payload.emoji)
- role = utils.get(message.guild.roles, id=config.roles[emoji])
- await user.remove_roles(role)
- print('[SUCCESS] Role {1.name} has been removed for user {0.display_name}'.format(user, role))
- except KeyError as e:
- print('[ERROR] KeyError, no role found for ' + emoji)
- except Exception as e:
- print(repr(e))
- client = MyClient()
- client.run(config.token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement