Alphexo
Alphexo

Reputation: 65

Checking discord command parameters

I dont have much to say, im trying to make an bot for discord using python.

The command is when I do

+permissions <user>

It shows a list of the user's permissions

Heres the problem: COMMAND

So, the permission im starting with is "Administrator"

And depending if the user has the permission it shows an unique message saying if he has the permission or not

As you see in here

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)

But it shows the error saying that I didnt inputed an argument (user)

ERROR ON DISCORD

ALL CODE

@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)

Upvotes: 0

Views: 750

Answers (1)

Tristo
Tristo

Reputation: 2398

Here is the working code

@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)

A couple of things, first off you don't need to use ctx.message.user.server_permissions if you've already initialised what the user is so just use user.server_permissions as ctx.message has no attribute called "user"

Secondly author is not defined, use ctx.author to display who sent the message

And lastly you misspelt :white_check_mark:

Hopefully this helped!

This is how it all looks in the end

Upvotes: 1

Related Questions