Why is my reason argument in my mute command using one word of the reason?

Viewed 42

My mute command is only getting one word of the reason I choose. Does anyone know why?

@client.command()
@commands.has_guild_permissions(kick_members=True)
async def tempmute(ctx, member: discord.Member, time, reason=None):
    muted_role = discord.utils.get(ctx.guild.roles, name="Muted")
    time_convert = {"s":1, "m":60, "h":3600,"d":86400, "w":604800, "mo":2592000, "y":31104000}
    tempmute = int(time[:-1]) * time_convert[time[-1]]
    await member.add_roles(muted_role)
    embed=discord.Embed(title=f"Member Muted", description=f"{member} has been muted for {time}.")
    embed.add_field(name=f"Moderator", value=f"{ctx.message.author}", inline=True)
    embed.add_field(name=f"Reason", value=f"{reason}", inline=True)
    await ctx.send(embed=embed)
    await asyncio.sleep(tempmute)
    await member.remove_roles(muted_role)
1 Answers

According to the discord.py documentation:

In a simple command defined as:

@bot.command()
async def echo(ctx, message: str):
   await ctx.send(message)

Calling it via ?echo a b c will only fetch the first argument and disregard the rest. To fix this you should either call it via ?echo "a b c" or change the signature to have “consume rest” behaviour. Example:

@bot.command()
async def echo(ctx, *, message: str):
   await ctx.send(message)

This will allow you to use ?echo a b c without needing the quotes.

In your case, either pass the reason surrounded in "quotes", or add an * argument between time and reason in your command signature.

Related