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

使用了不一致.py

当您键入/修补时

以下是控制台显示的

Ignoring exception in on_message
Traceback (most recent call last):
File "C:UsersFeNkaAppDataLocalProgramsPythonPython37-32libsite-packagesdiscordclient.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')

sendmessage.channel类的函数,因此可以访问self。它的调用可能看起来像:

def send(self, message):
#does things

self在这里是隐式的,你不发送它,这就是为什么当3实际发送时,它看起来像是传递了2参数

最新更新