TypeError:send()接受1到2个位置参数,但给出了3个 [英] TypeError: send() takes from 1 to 2 positional arguments but 3 were given

查看:97
本文介绍了TypeError:send()接受1到2个位置参数,但给出了3个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码的一部分

@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

used discord.py

当您输入/ patch

when you type /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

有什么问题吗?

推荐答案

您的通话应更改为

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

发送 message.channel 类,因此可以访问 self 。它的调用可能看起来像这样:

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 在这里是隐式的,您不发送它,这就是为什么当实际发送 3 时,似乎传递了 2 args的原因

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

这篇关于TypeError:send()接受1到2个位置参数,但给出了3个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆