TypeError: send() takes from 1 to 2 positional arguments but 3 were given

空扰寡人 提交于 2019-12-03 00:05:01

问题


Here is part of code

@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

used discord.py

when you type /patch

here's what the console shows

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

What could be wrong?


回答1:


Your call should be changed to

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

send is a function of the message.channel class, and thus has access to self. Its call probably looks something like:

def send(self, message):
    #does things

self is implicit here, you don't send it, and that's why it looks like 2 args were passed when 3 actually were sent



来源:https://stackoverflow.com/questions/53560166/typeerror-send-takes-from-1-to-2-positional-arguments-but-3-were-given

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!