disord.py中的on_reaction_add事件错误

问题描述 投票:0回答:1

我不明白为什么我给一个论据时说两个论点?

当我尝试执行此代码时

@bot.event
async def on_reaction_add(reaction):
    fp = reaction.message.guild.name
    l = reaction.message
    if os.path.isfile(ph + fp + '-bug.txt'):
        f = open(ph + fp + '-bug.txt')
        u = open(ph + fp + '-mod.txt')
        lines1 = u.readlines()
        lines = f.readlines()
        if str(l.channel.id) == lines1[0]:
            if reaction.emoji == "✅":
                channel = bot.get_channel(int(lines[0]))
                await channel.send(l.content)
            elif reaction.emoji == "❌":
                await l.delete()

我收到此错误

Traceback (most recent call last):
  File "C:\Users\---\PycharmProjects\---\venv\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
TypeError: on_reaction_add() takes 1 positional argument but 2 were given```


python discord discord.py
1个回答
0
投票

on_reaction_add事件需要参数reactionuser。您可以在this页面上阅读更多内容!

因此,为了使该事件正常进行,您应该像这样使用它:

@bot.event
async def on_reaction_add(reaction, user):
    print(reaction) # Prints information about the reaction that was given.
    print(user) # Prints information about the user that gave the reaction.

也:on_reaction_add() takes 1 positional argument but 2 were given表示应该接收两个参数,但是您的事件只能接收一个参数

© www.soinside.com 2019 - 2024. All rights reserved.