簡體   English   中英

這個 Discord Bot 中的錯誤在哪里?

[英]Where is the error in this Discord Bot who givea roles

這是代碼:

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith("!verify"):
        await message.author.send("Du wurdest Verifiziert")
        await client.add_roles(message.author, "721417651074891786")


client.run('Token')```

這就是錯誤:

Traceback (most recent call last):
  File "Discord.py", line 20, in on_message
    await client.add_roles(message.author, "721417651074891786")
AttributeError: 'Client' object has no attribute 'add_roles'

我不知道代碼有什么問題。 請幫我。 謝謝。

看起來您可能指的是一些舊文檔或教程。

在重寫 (v1.x) 中,添加角色等內容發生了變化 - 請參閱參考資料 - 以下是為您的案例編寫的代碼:

role = message.guild.get_role(721417651074891786) # IDs are now ints
await message.author.add_roles(role)

在繼續之前,我強烈建議您閱讀下面的鏈接(也許還可以找到更新的教程),以確保您知道何時查看重寫代碼而不是異步(v0.16.x)代碼並熟悉自己隨着變化。


參考:

暫無
暫無

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

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