0

I am trying to make a command that requires the "User" input, and I want it to send a message if the "User" isn't defined. Here's my code:

    if (User == True):
        await ctx.channel.send(f' {ctx.author.mention}! You got a {randRoll}! And {User} got a {randRoll2}!')
    else:
        await ctx.channel.send(f' {ctx.author.mention} You need to tell me who you want to battle!')
  • It's not very clear what you mean by defined here. I'm guessing `User` is a string, and if so what do you want to find users by? Do you want to check if anybody has that as a username, a nickname, a mention? – duckboycool Aug 03 '22 at 05:43
  • I'm using "User: discord.Member" to find User, making the author mention a person to battle. I want the bot to send a message if there isn't a user that was mentioned. – John Cowan Aug 03 '22 at 05:46
  • Give the user argument a default value `None` and check if it is `None` or not in the function. – 3nws Aug 03 '22 at 06:09
  • How do I give the User argument a default value of None? Or is the default value currently discord.Member? – John Cowan Aug 03 '22 at 06:12
  • Does this answer your question? [How do you make sure that user types full command in discord.py?](https://stackoverflow.com/questions/71771546/how-do-you-make-sure-that-user-types-full-command-in-discord-py) – 3nws Aug 03 '22 at 06:13
  • @JohnCowan `discord.Member` is just a type annotation for your linter and type checker. It has no effect on the runtime of your code. – 3nws Aug 03 '22 at 06:14
  • @3nws OK, thank you! The link you sent really cleared things up for me, thanks for the help! – John Cowan Aug 03 '22 at 06:17

0 Answers0