首页 > 解决方案 > 添加对消息的反应(discord.py)

问题描述

我想对在一个频道中发送的消息添加反应。我得到错误代码:

discord.errors.InvalidArgument: emoji argument must be str, Emoji, or Reaction not NoneType.

这是我的代码:

client = discord.Client()

if message.channel.id == 737668230012862514:
    emoji = client.get_emoji(310177266011340803)
    await message.add_reaction(emoji)

标签: pythonpython-3.xdiscord.py

解决方案


line:emoji argument must be str, Emoji, or Reaction not NoneType表示emoji设置为None,表示客户端找不到 id 的表情符号310177266011340803

从文档中可以看出,如果没有找到表情符号,则get_emoji返回。None

请确保这310177266011340803是一个有效的表情符号 ID,并且机器人可以访问表情符号所在的服务器。

要访问所有表情符号名称和 ID,您可以编写:

@client.event
async def on_ready():
    for emoji in client.emojis:
        print("Name:", emoji.name + ",", "ID:", emoji.id)

推荐阅读