AyeAreEm
AyeAreEm

Reputation: 343

Add a reaction to a ctx.send message in discord.py

I am making a poll command, the bot will send a ctx message and will say the poll question. I want to make it so when the poll message is sent, the bot adds two reaction, a thumbs up and a thumbs down. I have tried several different ways but non of them work. Here is the code from my latest try (everything is already imported)

reactions = ["👍", "👎"]

@bot.command(pass_context=True)
async def poll(self, ctx, message,*, question):
    poll_msg = f"Poll: {question} -{ctx.author}"
    reply = await self.bot.say(poll_msg)
    for emoji_id in reactions:
        emoji = get(ctx.server.emojis, name=emoji_id)
        await message.add_reaction(reply, emoji or emoji_id)

The code is all over the place because I tried putting different solutions together to see if it would work but it doesn't work at all.

Upvotes: 1

Views: 4487

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 60974

It looks like you're operating from some old examples. You should read the official documentation to find examples of the modern interfaces.

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

bot = commands.Bot("!")

reactions = ["👍", "👎"]

@bot.command()
async def poll(ctx, *, question):
    m = await ctx.send(f"Poll: {question} -{ctx.author}")
    for name in reactions:
        emoji = get(ctx.guild.emojis, name=name)
        await m.add_reaction(emoji or name)

Upvotes: 3

Related Questions