检查不和谐命令参数

时间:2018-08-23 12:06:05

标签: python discord.py

我没有太多话要说,我正试图用python创建一个不和谐的机器人。

命令是我做的

+permissions <user>

它显示用户权限列表

在这里出现问题: COMMAND

因此,以im开头的权限是“管理员”

根据用户是否获得许可,它会显示一条独特的消息,说明他是否具有许可

您在这里看到的

if ctx.message.user.server_permissions.administrator == True:
    embed.add_field(name="Administrator", value=":white_ckeck_mark: Permission Granted!", inline=True)
if ctx.message.user.server_permissions.administrator == False:    
    embed.add_field(name="Administrator", value=":x: Permission Denied!", inline=True)

但是它显示了错误,提示我没有输入参数(用户)

ERROR ON DISCORD

所有代码

@bot.command(pass_context=True)
async def permissions(ctx, user: discord.Member):
    embed = discord.Embed(name="USER_PERMISSIONS", description="------------------------------------------------------", color=0x0099ff)
    embed.set_author(name="USER_PERMISSIONS: {}'s Permissions".format(user.name))
if ctx.message.user.server_permissions.administrator == True:
    embed.add_field(name="Administrator", value=":white_ckeck_mark: Permission Granted!", inline=True)
if ctx.message.user.server_permissions.administrator == False:    
    embed.add_field(name="Administrator", value=":x: Permission Denied!", inline=True)
if ctx.message.user.server_permissions.view_audit_logs == True:
    embed.add_field(name="View Audit Logs", value=":white_ckeck_mark: Permission Granted!", inline=True)
if ctx.message.user.server_permissions.view_audit_logs == False:
    embed.add_field(name="View Audit Logs", value=":x: Permission Denied!", inline=True)
embed.set_thumbnail(url=user.avatar_url)
embed.set_footer(text="Requested by {}".format(author), icon_url=author.avatar_url)
await bot.say(embed=embed)

1 个答案:

答案 0 :(得分:1)

这是工作代码

@bot.command(pass_context=True)
async def permissions(ctx, user: discord.Member):
  embed = discord.Embed(name="USER_PERMISSIONS", description="------------------------------------------------------", color=0x0099ff)
  embed.set_author(name="USER_PERMISSIONS: {}'s Permissions".format(user.name))
  if user.server_permissions.administrator == True:
    embed.add_field(name="Administrator", value=":white_check_mark:  Permission Granted!", inline=True)
  if user.server_permissions.administrator == False:    
    embed.add_field(name="Administrator", value=":x: Permission Denied!", inline=True)
  if user.server_permissions.view_audit_logs == True:
    embed.add_field(name="View Audit Logs", value=":white_check_mark:  Permission Granted!", inline=True)
  if user.server_permissions.view_audit_logs == False:
    embed.add_field(name="View Audit Logs", value=":x: Permission Denied!", inline=True)
  embed.set_thumbnail(url=user.avatar_url)
  embed.set_footer(text="Requested by {}".format(ctx.message.author), icon_url=ctx.message.author.avatar_url)
  await bot.say(embed=embed)

有两件事,首先,如果您已经初始化了用户身份,则无需使用ctx.message.user.server_permissions,所以只需使用user.server_permissions,因为ctx.message不会调用任何属性“用户”

第二个作者未定义,请使用ctx.author显示发送消息的人

最后,您拼错了:white_check_mark:

希望这有所帮助!

This is how it all looks in the end