在 discord.py 中添加对 ctx.send 消息的反应

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

我正在发出投票命令,机器人将发送一条 ctx 消息并说出投票问题。我想让它在发送轮询消息时,机器人添加两个反应,一个竖起大拇指和一个竖起大拇指。我尝试了几种不同的方法,但没有一种有效。这是我最近尝试的代码(所有内容都已导入)

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)

代码到处都是,因为我尝试将不同的解决方案放在一起看是否可行,但根本行不通。

看起来你是在用一些旧的例子来操作。您应该阅读 official documentation 以查找现代界面的示例。

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)