【问题标题】:Add a reaction to a ctx.send message in discord.py在 discord.py 中添加对 ctx.send 消息的反应
【发布时间】:2020-05-07 11:16:34
【问题描述】:

我正在发出投票命令,机器人将发送一条 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)

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

【问题讨论】:

    标签: python-3.x discord.py-rewrite


    【解决方案1】:

    看起来您正在使用一些旧示例进行操作。您应该阅读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)
    

    【讨论】:

    • 我输入了代码,它立即生效!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2019-09-06
    • 2020-10-27
    • 2022-01-14
    相关资源
    最近更新 更多