【发布时间】:2021-04-20 22:12:53
【问题描述】:
我正在开发一个 discord.py 机器人,没问题,我的代码运行良好,但我想知道如何授予机器人所有者的权限,他应该删除一个赋予所有高权限的角色,(所有权限位于服务器>服务器设置>角色>角色名称),所以他应该删除他的角色,但他给出了这个错误:
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
@bot.command(name="godRemove")
async def godremover(ctx, persona, numerogod):
channel = bot.get_channel(id=786285288469037197)
numerogod=int(numerogod)
if not numerogod>1:
numerogod=1
#hasadded=False
#hasgod=False
rolenumber=0
try:
guild=ctx.guild
if ctx.author.name in canAddGod:
for i in guild.members:
if str(i)[:-5].lower().strip()==persona.lower().strip():
for role in i.roles:
#if str(role)=="God":
#hasgod=True
if representsint(str(role)):
rolename=str(int(str(role))-numerogod).strip().lower()
rolenumber=int(rolename)
if rolenumber>1:
if discord.utils.get(ctx.guild.roles, name=rolename)!=None:
togiverole=discord.utils.get(guild.roles, name=rolename)
await i.add_roles(togiverole)
await i.remove_roles(role)
#hasadded=True
await channel.send(removedliteral)
return
else:
togiverole=await ctx.guild.create_role(name=str(int(str(role))+numerogod), colour=discord.Colour(0xFFFFFF))
await i.add_roles(togiverole)
await i.remove_roles(role)
#hasadded=True
await channel.send(removedliteral)
return
elif rolenumber==0:
await i.remove_roles(discord.utils.get(ctx.guild.roles, name="God"))
else:
await i.remove_roles(discord.utils.get(ctx.guild.roles, name="God"))
await i.remove_roles(role)
except Exception:
traceback.print_exc()
await channel.send(errorliteral)
代码有点乱,但是我有一段时间没有用python编写代码了,所以在这里稍微解释一下(ps,这是我想添加到我的服务器的一个有点有趣的东西,就像,每个人都是上帝,如果他们做了一些有趣的事情,我会添加上帝,如果没有,我会删除上帝,所以如果他们没有足够的上帝(
回答: 在角色列表中将应该拥有更多权限的角色移到应该“支配”的角色之上!
【问题讨论】:
标签: python discord discord.py