簡體   English   中英

TypeError:send()接受1到2個位置參數,但給出了3個

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

這是代碼的一部分

@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

有什么事嗎

您的通話應更改為

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參數時看起來像傳遞了2 args的原因

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM