0

I've been trying to create a set up where there is one permanent message in a text channel that users could react to in order to receive a specific role. From what I can tell, I've come across a way of doing this but I'm missing something that will allow it to work. Here's what I have so far:

import discord
from discord.ext.commands import Bot
from discord.ext import commands
from discord.utils import get

bot_prefix = "r!"
bot = commands.Bot(command_prefix=bot_prefix)

@bot.event
async def on_ready():
    print("Bot Online!")
    print("Name: {}".format(bot.user.name))
    print("ID: {}".format(bot.user.id))
    await bot.change_presence(game=discord.Game(name='Visit the roles channel!'))

class Main_Commands():
    def __init__(self, bot):
    self.bot = bot

# r!ping
@bot.command(pass_context=True)
async def ping(ctx):
    await bot.say("Pong!")

@bot.event
async def on_reaction_add(reaction, user):
    role = discord.utils.get(WHAT GOES HERE, name="463359356281421844")
    roleChannelId = "463374724702142464"
    if reaction.message.channel.id != roleChannelId:
        return
    if str(reaction.emoji) == u"\U0001F534":
        await bot.add_roles(user, role)

bot.run("TOKEN")

I can't seem to figure out what exactly I need to list as my iterable. I know it needs to get the roles from the server, I just don't know how. In addition, I've come to understand that on_reaction_add really only works if the message is sent after the bot is booted, which is no good for many reasons. Can you iterable I'm looking for and is there a way to avoid the pitfall of on_reaction_add?

Lemon
  • 13
  • 1
  • 7
  • The rewrite version offers [`on_raw_reaction_add`](https://discordpy.readthedocs.io/en/rewrite/api.html#discord.on_raw_reaction_add). You're probably looking for the `roles` attribute of a `Server` or `Guild` object.. – Patrick Haugh Jul 03 '18 at 01:35
  • I tried replacing `on_reaction_add` with `on_raw_reaction_add` and put both all of the following in the "WHAT GOES HERE" section: `server.roles` , `user.server.roles`, `server.guild`, and `user.guild.roles` and nothing has happend at all. Did I do something wrong? – Lemon Jul 03 '18 at 01:50
  • You're probably using the `async` branch of discord.py, which doesn't have `on_raw_reaction_add`. There are a few options: [upgrade to the rewrite branch](https://stackoverflow.com/questions/50686388/how-to-install-discord-py-rewrite), post a new message in the channel when your bot comes online, users ask for colors using a command instead, find some way to insert the old message into the message cache when the bot starts (might not be possible/easy). – Patrick Haugh Jul 03 '18 at 02:04
  • And it would be `reaction.message.server.roles`. – Patrick Haugh Jul 03 '18 at 02:06

0 Answers0