首页 > 解决方案 > 如何在没有类型错误的情况下使用 add_reaction()?

问题描述

我正在尝试应朋友的要求制作口袋妖怪中心命令。计划是在用户对“A”表情符号 (:a:) 做出反应时继续对话,因此我试图让机器人首先对自己的消息做出反应。这是代码

@bot.command()
async def joy(ctx):
    msg = await ctx.send(f'Welcome to our Pokémon Center!')
    emoji = bot.get_emoji(706288524089098360)
    await msg.add_reaction(msg,emoji)

每当我运行它时,我都会收到此错误:

TypeError: add_reaction() takes 2 positional arguments but 3 were given

标签: pythondiscorddiscord.py

解决方案


There is no need to put msg as parameter of add_reaction(), just use msg.add_reaction(emoji) with a unicode emoji. Here is the doc for add_reaction()

The self variable mustn't be specified, add_reaction() gets it form msg before the dot by himself in msg.add_reaction(emoji).


推荐阅读