How Do I Make Mentioning A Member Optional Within A Command?
I've created a code that sends the gif of a hug on command and specifies who it's to, however, I also want to make it optional to mention a member. the current code is: @client.com
Solution 1:
You can define your member
argument to None
by default. If you invoke your command without mentionning anyone, member
will have None
as value and the if member
statement won't be triggered.
Also, by defining member
as a Member
object in the function's arguments, you'll be able to access the mentionned member's informations.
Here's how you use it :
@client.command()asyncdefhug(ctx, member: discord.Member = None):
if member:
embed = discord.Embed(title=f'{ctx.author} has sent a hug to {member}!',
description='warm, fuzzy and comforting <3',
color=0x83B5E3)
else:
embed = discord.Embed(color=0x83B5E3)
image = random.choice([(url1), (url2),....(url10)])
embed.set_image(url=image)
await ctx.channel.send(embed=embed)
Post a Comment for "How Do I Make Mentioning A Member Optional Within A Command?"