@commands.group(aliases=['nick'], invoke_without_command=True)
async def nickname(self,ctx):
embed = discord.Embed(description="<:oxmark:839069221207670804> "+f"Unsuccessful, use the proper format. [-help].", color=discord.Color.orange())
return await ctx.reply(embed=embed, mention_author=False)
@nickname.group()
async def add(self,ctx, member: discord.Member, *, new_name):
if len(new_name) > 32:
embed = discord.Embed(description="<:oxmark:839069221207670804> "+f"Unsuccessful, provide 32 > members.", color=discord.Color.orange())
return await ctx.reply(embed=embed, mention_author=False)
elif member.top_role > ctx.author.top_role:
embed = discord.Embed(description="<:oxmark:839069221207670804> "+f"Unsuccessful, targets role in the hierarchy is higher than yours.", color=discord.Color.orange())
await ctx.reply(embed=embed, mention_author=False)
elif ctx.me.top_role <= member.top_role:
embed = discord.Embed(description="<:oxmark:839069221207670804> "+f"Unsuccessful, my role in the hierarchy lesser than targets.", color=discord.Color.orange())
await ctx.reply(embed=embed, mention_author=False)
elif member.id == ctx.guild.owner:
embed = discord.Embed(description="<:oxmark:839069221207670804> "+f"Unsuccessful, owners nickname can't be changed.", color=discord.Color.orange())
await ctx.reply(embed=embed, mention_author=False)
return
else:
try:
await member.edit(nick=new_name)
embed = discord.Embed(description = "<:ocheckmark:839069223749812264> "+f"**Successfully changed {member.name}s nickname to {new_name}** ", color = discord.Colour.orange())
await ctx.reply(embed=embed, mention_author=False)
except Exception as e:
print(e)
@nickname.group(aliases=['rem'])
async def remove(self,ctx,member: discord.Member):
if member.top_role > ctx.author.top_role:
embed = discord.Embed(description="<:oxmark:839069221207670804> "+f"Unsuccessful, targets role in the hierarchy is higher than yours.", color=discord.Color.orange())
await ctx.reply(embed=embed, mention_author=False)
elif ctx.me.top_role <= member.top_role:
embed = discord.Embed(description="<:oxmark:839069221207670804> "+f"Unsuccessful, my role in the hierarchy lesser than targets.", color=discord.Color.orange())
await ctx.reply(embed=embed, mention_author=False)
elif member.id == ctx.guild.owner:
embed = discord.Embed(description="<:oxmark:839069221207670804> "+f"Unsuccessful, owners nickname can't be changed.", color=discord.Color.orange())
await ctx.reply(embed=embed, mention_author=False)
return
else:
try:
name = member.name
await member.edit(nick=name)
embed = discord.Embed(description = "<:ocheckmark:839069223749812264> "+f"**Successfully removed {member.name}s nickname** ", color = discord.Colour.orange())
await ctx.reply(embed=embed, mention_author=False)
except Exception as e:
print(e)
@nickname.error
async def nickname_error(self,ctx, error):
if isinstance(error, commands.MemberNotFound):
embed = discord.Embed(description="<:oxmark:839069221207670804> "+f"Unsuccessful, I can't find that user in this guild.", color=discord.Color.orange())
await ctx.reply(embed=embed, mention_author=False)
我做了一个改变另一个用户昵称的命令,虽然它工作得很好,但有一些缺陷。首先,如果我尝试更改所有者昵称,它只会打印出 403 Forbidden (error code: 50013): Missing Permissions
表示 elif member.id == ctx.guild.owner:
失败。最后,如果我提供了一个无效的成员,它既不会回复也不会打印出错误。
答案 0 :(得分:0)
我认为问题出在这里:
elif member.id == ctx.guild.owner:
你能用这个替换并重试吗:
elif member.id == ctx.guild.owner.id: