【问题标题】:Discord.py adding reactionsDiscord.py 添加反应
【发布时间】:2021-03-11 17:45:39
【问题描述】:

我想做一个投票命令,机器人会发送这样的消息:https://i.stack.imgur.com/SlGaw.png 并对此添加两个反应::one::two:,这是我的实际代码:

@bot.command()
async def poll(ctx, quest, opt1, opt2):
    embed=discord.Embed(color=0x29db4d)
    embed.add_field(name=quest, value=f":one: - {opt1}, :two: - {opt2}", inline=True)
    await ctx.send(embed=embed)
    await ctx.add_reaction('one')
    await ctx.add_reaction('two')

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    添加反应时,您应该使用unicode(标准表情符号)或name:id(或者<:name:id>)自定义表情符号。在您的情况下,:one::two: 都是标准表情符号。

    另外,我假设您想将您的反应添加到您发送的实际嵌入中,而不是调用它的命令。 Messageable.send() 返回它发送的消息的discord.Message 实例,因此您可以使用message = ctx.send(...)

    @bot.command()
    async def poll(ctx, quest, opt1, opt2):
        embed=discord.Embed(color=0x29db4d)
        embed.add_field(name=quest, value=f":one: - {opt1}, :two: - {opt2}", inline=True)
        message = await ctx.send(embed=embed)
        await message.add_reaction("1️⃣")
        await message.add_reaction("2️⃣")
    

    【讨论】:

    • 您可以通过在它之前使用 `` 以不和谐的方式发送原始表情符号。
    • 不幸的是,它不起作用。我没有收到任何错误,只是机器人没有添加任何反应。给留言
    • 它是否有权在该频道中添加反应?我刚刚测试了这段代码,它确实有效。你可以用你的机器人在 DM 中试一试吗?
    • 它有权限,我在 dm 中尝试过,但仍然没有。哎呀,对不起,是我的错。感谢您的帮助和回复!
    猜你喜欢
    • 2021-04-18
    • 2020-10-03
    • 1970-01-01
    • 2019-09-06
    • 2022-01-02
    • 2020-10-27
    • 1970-01-01
    • 2020-11-07
    • 2021-12-18
    相关资源
    最近更新 更多