【发布时间】:2019-09-03 02:00:52
【问题描述】:
我一直在编写一个不和谐的机器人,对于它的禁令命令,这是我使用的代码:
@client.command(aliases=['Ban'])
async def ban(ctx, member: discord.Member, days: int = 1):
if get(ctx.author.roles, id=548841535223889923):
await member.ban(delete_message_days=days)
await ctx.send("Banned {}".format(ctx.author))
else:
await ctx.send(ctx.author.mention + " you don't have permission to use this command.".format(ctx.author))
但是,如果我尝试在其他服务器上使用它,它只会告诉我我没有所需的角色.. 那么如何获取机器人自动加入的新服务器的角色 ID,或者是否有其他方法可以实现这一点?
【问题讨论】:
-
每个角色都有唯一的ID,即使是同名的角色也有不同的ID,但单独的角色来自不同的服务器。您现在的操作方式只能允许
ban命令为 1 个角色工作,仅此而已。这也意味着它仅适用于具有该 1 个角色的 1 个服务器。 -
我已经解决了,你可以使用:
@commands.has_permissions(<kick/ban)_members=True)
标签: discord.py