【发布时间】:2021-07-15 02:53:38
【问题描述】:
机器人工作得很好,但是当我添加时
@commands.has_permissions(administrator=True)
然后代码中断,我得到这个错误:
文件“C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\abc.py”,第 427 行,在 permissions_for 角色 = member.roles AttributeError:“用户”对象没有属性“角色”
但问题是错误不在机器人代码所在的文件中。错误出现在一些随机的站点包文件夹中。
整个命令代码:
@client.command(aliases=["Server"])
@commands.has_permissions(administrator=True)
async def ServerInfo(ctx):
guild = ctx.guild
embed = discord.Embed(title="Server Info", colour = 0xFF0000, timestamp=datetime.datetime.utcnow())
embed.add_field(name = "Server name:", value = f"{guild.name}", inline = False)
embed.add_field(name = "Members:", value = f"{len(guild.members)}", inline = False)
embed.add_field(name = "Boosters", value = f"{guild.premium_subscribers}", inline = False)
await ctx.send(embed=embed)
print("ServerInfo works")
【问题讨论】:
-
您确定错误中的所有行都没有引用您的代码吗?
-
是的,因为代码只有 70 行
-
尝试删除@commands.has_permissions 装饰器,然后执行
print(type(ctx), type(ctx.author), type(ctx.message.author)) -
这是我运行命令时得到的:
标签: python discord discord.py