1
votes

I am setting up a mute command for my new discord bot, I am fairly new to the discord.py stuff, and do not understand what is going wrong. I keep getting the error that a member is not being specified, when it clearly is.

I have tried many tutorials on youtube etc, but it always skims over a detail or two so I can't fully figure it out. I would appreciate it if someone could correct my code, because I am still learning discord.py.

@client.command()
async def mute(context, member: discord.Member=None):
    if not member:
        await client.say('Please specify a member')
        return
    role = get(member.server.roles, name="Muted")
    await client.add_roles(member, role)
    await client.say('{member.mention} was muted.')

It is just supposed to add the muted role to someone, and be done with it. I am having the same issue with specifying a member when using my ban and kick commands too, which are done in the same fashion.

I am open to all suggestions, thank you!

1
Are you seeing an exception, or getting the "Please specify..." message? How are you invoking this? If you're getting an exception, could you share the full text of the exception?Patrick Haugh
I am not getting any errors in my shell, but instead the bot asks me to specify a member, as it says on line 4 of my code. It is honestly confusing mexupaii

1 Answers

1
votes

You need to change the decorator to @client.command(pass_context=True). The member name is being assigned to context, leaving member to take the default value.

@client.command(pass_context=True)
async def mute(context, member: discord.Member=None):
    if not member:
        await client.say('Please specify a member')
        return
    role = get(member.server.roles, name="Muted")
    await client.add_roles(member, role)
    await client.say(f'{member.mention} was muted.')  # You forgot the f

Also, I would probably just let the conversion fail and then handle the error:

@client.command(pass_context=True)
async def mute(ctx, member: discord.Member):
    role = get(member.server.roles, name="Muted")
    await client.add_roles(member, role)
    await client.say(f'{member.mention} was muted.')

@mute.error:
async def mute_error(error, ctx):
    if isinstance(error, ConversionError):
        await client.send_message(ctx.message.channel, 'Please specify a member')
    else:
        raise error