[英]Command for roles in discord.py
我正在嘗試為我的 discord 機器人添加一個驗證系統,其中一個人執行 c.verify 以獲得已驗證的角色,但是我在授予角色時遇到了麻煩,而且我發現的所有內容都不起作用。 這就是我所擁有的:
@commands.command(pass_context=True)
async def verify(self, ctx):
role = get(ctx.author.roles, name="TOS Verified")
if ctx.channel.id == 769016529450303519:
await ctx.message.delete()
await ctx.send(f"{ctx.author.mention} has been verified.")
sleep(1)
await ctx.channel.purge(limit = 1)
await bot.add_roles(ctx.message.author, role)
else:
await ctx.message.delete()
await ctx.send("You can not verify here.")
我得到的錯誤是“bot 沒有屬性 add_roles”。 一切正常,直到它必須添加角色,但我不知道為什么我不能添加角色。
好吧,讓我們從頂部開始,
role = get(ctx.author.roles, name="TOS Verified")
在這里,您試圖從運行命令的人那里獲得一個名為TOS Verified
的角色,這是沒有意義的,因為如果他們試圖驗證他們將不會擁有該角色。 我們實際上想從公會的角色中得到這個:
role = get(ctx.guild.roles, name="TOS Verified")
第二個問題
await bot.add_roles(ctx.message.author, role)
Bot
沒有add_roles
屬性,查看文檔它告訴我們它實際上是 Member 的方法。 在您的情況下,您的 Member 對象將是ctx.author
。
await ctx.author.add_roles(role)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.