Home > OS >  Discord.py Random Variabel Input / Ouput
Discord.py Random Variabel Input / Ouput

Time:11-12

I would like to expand my Discord Bot with a new randomizer function. I always want to enter the values/variables manually, for example:

Input: !random text1 text2 text3 Output: The result is "text2"

I need the whole thing in Discord.py (Python) and without slash (/) commands. I tried:

@bot.command()
async def r(ctx, str, name1: str, name2):
    list = [str(name1), str(name2)];
    embed = discord.Embed(
        colour=0xc81f9f,
        title="Rating",
        description=f"{ctx.author.mention} {random.choice(list)} is your rating"
    )
    await ctx.send(embed=embed)

CodePudding user response:

Instead of manully doing name1 , name2 you could use *args to grab arguments,

@bot.command()
async def r(ctx, *args):
    embed = discord.Embed(
        colour=0xc81f9f,
        title="Rating",
        description=f"{ctx.author.mention} {random.choice(args)} is your rating"
    )
    await ctx.send(embed=embed)
  • Related