[英]How can I add a role to a user with discord.py/my discord bot?
我在 python 中制作了一個小小的 discord bot 來在我的服務器上運行它,但我不想在我的服務器中有隨機數,所以我創建了這個命令。
當執行“代碼”(也可以看作是密碼)時,用戶獲得用戶角色(來自訪問者角色)
我的代碼:
@client.command()
async def test(ctx):
user = ctx.message.author
await user.add_roles(discord.utils.get(user.guild.roles, id=...))
我得到的錯誤:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception:
Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
到目前為止我嘗試過的:
那么,有人可以幫我嗎?
我發現了一個類似的問題,有一些答案,所以我調整了代碼以找出一些東西,試試這個,它對我有用:
@client.command()
async def test(ctx):
user= ctx.message.author
role = (discord.utils.get(user.guild.roles, id=insert id here))
await ctx.author.add_roles(role)
await ctx.send("Successfully assigned {}!".format(role.mention))
client.run('token for obvious reasons here')
您可以在Discord 開發人員門戶看到錯誤代碼,錯誤代碼 50013 是You lack permissions to perform that action
還是機器人無法執行您希望它執行的操作。 更多信息在這里。
注意:您的代碼可能有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.