'discord.py - Is there a way to make it so it can @ someone only for question area
I was wondering with this code is there a way to remove the question part and make it so that it can only @ someone, so you do $hug and then @ someone in order for the bot respond.
@client.command(name='hug', help='Put a persons name in front of the command and the bot will tell you how many hugs you shall recieve from them.')
async def hugs(ctx, *, question):
numHugs = [
"No hugs for you."
"1 hug",
"2 hugs",
"3 hugs",
"4 hugs",
"5 hugs"
"6 hugs",
"7 hugs",
"8 hugs",
"9 hugs",
"10 hugs",
"11 hugs",
"12 hugs",
"13 hugs",
"14 hugs",
"15 hugs",
"16 hugs",
"17 hugs",
"18 hugs",
"19 hugs",
"20 hugs",
"**INFINITE HUGS**"
]
await ctx.send(f'**PERSON**\n\n{question}\n\n**HOW MANY TIMES YOU ARE GOING TO BE HUGGED**\n\n{random.choice(numHugs)}')
Solution 1:[1]
If you want to make the bot reply and mention the user when you use the command, you can do it using the following code:
@client.command(name='hug', help="Put a person's name in front of the command and the bot will tell you how many hugs you shall receive from them.")
async def hugs(ctx, user_to_hug:discord.User):
numHugs = [
"No hugs for you."
"1 hug",
"2 hugs",
"3 hugs",
"4 hugs",
"5 hugs"
"6 hugs",
"7 hugs",
"8 hugs",
"9 hugs",
"10 hugs",
"11 hugs",
"12 hugs",
"13 hugs",
"14 hugs",
"15 hugs",
"16 hugs",
"17 hugs",
"18 hugs",
"19 hugs",
"20 hugs",
"**INFINITE HUGS**"
]
await ctx.send(f'**PERSON**\n\n{user_to_hug.mention}\n\n**HOW MANY TIMES YOU ARE GOING TO BE HUGGED**\n\n{random.choice(numHugs)}')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CrazyChucky |
