簡體   English   中英

Python - Discord.py - 嘗試通過 DM 接收用戶響應時出現意外關鍵字參數錯誤

[英]Python - Discord.py - wait_for() unexpected keyword argument error when trying to receive response from user via DM

我正在嘗試設置一個機器人功能,該功能會發送一個 DM 要求用戶輸入。同意作為消息,當他們這樣做時。 然后他們將被分配更高權限的角色(“@approved”)。

我正在使用 Patrick 在以下鏈接上發布的代碼:

有人加入時創建規則協議

DM 正在按預期發送(見下文)

分米

但我收到一個錯誤:


msg = await client.wait_for("message", channel=dm.channel, author=member, check=check)
TypeError: wait_for() got an unexpected keyword argument 'channel'

我已嘗試刪除通道參數,因為我不確定是否仍然需要此參數,但錯誤仍然存在,預計它會顯示意外的關鍵字參數“作者”。

我檢查了文檔,但不確定為什么會出現此錯誤。

我正在使用的代碼如下:

@client.event
async def on_member_join(member):
    print("A member just joined and his name is" + member.name)
    approved = discord.utils.get(member.guild.roles, name="approved")
    
    Rules = "1. Do not DM the Owner or any other staff unless they have DMed you first! \n 2. Be kind, \n 3. Use common sense, \n 4. No swearing, \n 5. No racism or bullying, \n 6. No advertising, \n 7. Do not chat in #music Text or Voice channels, \n 8. Do not spam #applications if your application is accepted or denied! This is only to be used for submitting and staff members replying to the application. \n 9. Do not use or abuse bot commands you should not be using! \n 10. Do not @ any staff members unless it is an emergency.  "

    # DM user with rules
    await member.send("Hello {0.mention}, welcome to {0.guild.name}".format(member))
    await member.send(Rules)
    dm = await member.send("Type !agree to agree")

    # get response
    check = lambda s: s.lower().startswith("!agree")
    msg = await client.wait_for("message", channel=dm.channel, author=member, check=check)

    await client.add_roles(member, approved)

感謝任何能夠提供幫助或解決此問題的人。

當您復制代碼而不檢查結構時會發生這種情況。 該代碼已過期並且屬於舊庫。 自新更新以來,情況發生了很大變化。

我已經進行了更正,它應該可以工作。

@client.event
async def on_member_join(member):
    print("A member just joined and his name is" + member.name)
    approved = discord.utils.get(member.guild.roles, name="approved")
    
    Rules = " YOUR RULES"

    # DM user with rules
    await member.send("Hello {0.mention}, welcome to {0.guild.name}".format(member))
    await member.send(Rules)
    dm = await member.send("Type !agree to agree")

    #VERIFY DM Channel == Message Channel
    def check(message):
        return message.channel == dm.channel
    #Since the Library has changed, This is the correct FORM.
    msg = await client.wait_for('message',check = check)
    #Also, For adding the roles, You should use this format. The Client one is old and not working anymore.
    await member.add_roles(approved)

暫無
暫無

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

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