Discord.py 让 discord 机器人用几个表情对消息做出反应

Discord.py make discord bot react to message with several emotes

我知道如何让机器人对消息做出反应,但我受困于我的项目,我只是 运行 经常遇到麻烦。我想使用语法 -react [message ID] [emote1] [emote2] [emote 3] [emote ...] 执行一个命令,该命令使用我放在 ID 后的表情对属于 ID 的消息做出反应。

我知道如何让机器人对相同的消息做出相同的表情反应,并尝试使用代码让它对其他消息做出反应:

@client.command()
async def react(ctx, ID):
    emotes = ['❤️', '']
    msg = message.fetch_message(ID)
    for emote in emotes:
        await ctx.msg.add_reaction(emoji=emote)

但这总是在 msg = message.fetch_message(ID) 中输出 NameError: name 'message' is not defined,另外我一点也不知道如何让它与自己选择的表情一起工作。

所以,我的主要问题是:

  1. 如何让机器人对特定消息做出反应? (已解决)
  2. 如何使用自己指定的表情来制作它?

更新:第一个问题解决了,我只需要添加

message_id = ID
    msg = await ctx.fetch_message(message_id)

但我仍然坚持让它对用户给定的表情做出反应,而不是硬编码的表情。

  1. 您没有定义 message 变量,这就是它抛出该错误的原因。
  2. ID参数为字符串,ids必须为整数
  3. ctx 没有属性 msg 它是 message

另外,要实现表情符号,您只需将它们作为元组传递并使用 for 循环遍历即可。

@client.command()
async def react(ctx, ID: int, *emojis):
    message = ctx.fetch_message(ID)

    for emoji in emojis:
        await message.add_reaction(emoji)
        # Or if you want to add the reactions to the message which invoked the command
        await ctx.message.add_reaction(emoji)