您好我在如何通过使用角色来防止会员获得其他会员头像,因为您可以看到具有私人头像角色的会员将保护他们的头像。这就是我在.py
中对此进行编码的方式class Avatar:
"""Returns members avatar."""
def __init__(self, bot):
self.bot = bot
@commands.command(pass_context=True)
@commands.cooldown(5, 60, commands.BucketType.user)
async def avatar(self, context, member: discord.Member):
"""Returns members avatar."""
role = discord.utils.get(member.server.roles, name="Private Avatar")
author = context.message.author.mention
mention = member.mention
if role in member.roles:
pa = "This members avatar is private"
await self.bot.say(pa)
return
avatar = "{0} here is {1}'s avatar"
u = member.avatar_url
url = process_avatar(u)
embed = discord.Embed(description=avatar.format(author, mention), colour=discord.Colour.blue())
embed.set_image(url=u)
await self.bot.say(embed=embed)
我挣扎的代码行是这一行
if role in member.roles:
pa = "This members avatar is private"
await self.bot.say(pa)
return
这基本上应该输出消息"这个成员头像是私有的"没有检索头像但它仍然检索带有消息的头像。
非常感谢您的帮助。
答案 0 :(得分:0)
你过度复杂了。只需使用else:
,就像这样:
class Avatar:
"""Returns members avatar."""
def __init__(self, bot):
self.bot = bot
@commands.command(pass_context=True)
@commands.cooldown(5, 60, commands.BucketType.user)
async def avatar(self, context, member: discord.Member):
"""Returns members avatar."""
role = discord.utils.get(member.server.roles, name="Private Avatar")
author = context.message.author.mention
mention = member.mention
if role in member.roles:
pa = "This members avatar is private"
await self.bot.say(pa)
else:
avatar = "{0} here is {1}'s avatar"
u = member.avatar_url
url = process_avatar(u)
embed = discord.Embed(description=avatar.format(author, mention), colour=discord.Colour.blue())
embed.set_image(url=u)
await self.bot.say(embed=embed)
P.S。:理论上,您的代码应该有效。除非有一些我没有看错的事,那就是。我还必须注意,仅仅因为机器人不会获取它,并不意味着客户端不能。头像是公开的。