TypeError:send()接受1到2个位置参数,但给出了3个

时间:2018-11-30 15:14:17

标签: python discord discord.py

这是代码的一部分

@client.event
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return
    # The command /patch return a link with the latest patch note
    if message.content.startswith('/patch'):
        await message.channel.send(message.channel, 'Last patchnotes: https://www.epicgames.com/fortnite/en/news')
    # The command /rank return attribute a rank according to the K/D of the user

使用的discord.py

键入/ patch

这是控制台显示的内容

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\FeNka\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\client.py", line 227, in _run_event
    await coro(*args, **kwargs)
  File "bot.py", line 107, in on_message
    await message.channel.send(message.channel, 'Last patchnotes: https://www.epicgames.com/fortnite/en/news')
TypeError: send() takes from 1 to 2 positional arguments but 3 were given

怎么了?

1 个答案:

答案 0 :(得分:1)

您的通话应更改为

await message.channel.send('Last patchnotes: https://www.epicgames.com/fortnite/en/news')

sendmessage.channel类的函数,因此可以访问self。它的调用可能类似于:

def send(self, message):
    #does things

self在这里是隐式的,您不发送它,这就是为什么当实际发送2时传递了3个参数的原因