Send a different message if specific id uses the command

I want to make this command so that when the specific id uses it, it will send another message.

    @commands.command(pass_context=True)
    async def ship(self, ctx):
        user = choice(ctx.message.channel.guild.members)
        em = Embed(
            title = 'شیپ های زیبا',
            description = f'{ctx.message.author.mention} X {user.mention}',
            colour = ctx.guild.me.top_role.colour
        )
        await ctx.send(embed=em)

Solution 1:

To tackle this problem, my strongest recommendation is to use an if-else statement, where you check if the ctx.author.id is the same as a set id that you provide. Do have a look at the code snippet below, along with an image of a working example.

@commands.command()
async def ship(self, ctx):
    if ctx.author.id == 000000: # replace this with the user's id
        # code runs if these two ids are equal to each other
        # do something here

    # if you want to use multiple users, use an elif statement
    elif ctx.author.id == 0000: # replace this with another user's id
        # do something here

    else: # 'else' if the author is none of these ids
        # do something else

Image example of the above code

Other Links:

  • How to check if message was sent by certain user - Stackoverflow
  • Check if a specific user did a command - Stackoverflow
  • Python conditions (if, elif, else) - Stackoverflow

Edit (answering question in comments)

To my knowledge, a good way to get a random user that isn't the author is by using a while True loop. With every iteration, the bot would check if the randomly chosen user is the author, and if it is not, the bot will break the loop and send the user. Otherwise, it would continue looping until the user is not equal to the author. Do view the code snippet below.

while True:
    user = random.choice(ctx.guild.members)
    if user == ctx.author:
        continue # Restarts the loop
    break # Ends the loop

await ctx.send(user)

Above code snippet working as expected