Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord mute command

I'm currently trying to make a discord bot with the ability to .mute a user. I have created this script so far that allows people with a "staff" role to run the command, and gives the tagged user a "Muted" role. It also creates one if it doesn't exist already. The problem is the code below does not work. It doesn't say anything in the console but if you have the staff role and you run the command nothing happens.

@commands.has_role("staff")
async def mute(ctx, member: discord.Member=None):
    guild = ctx.guild
    if (not guild.has_role(name="Muted")):
        perms = discord.Permissions(send_messages=False, speak=False)
        await guild.create_role(name="Muted", permissions=perms)
    role = discord.utils.get(ctx.guild.roles, name="Muted")
    await member.add_roles(role)      
    print("🔨 "+member+" was muted.")
    if (not member):
        await ctx.send("Please specify a member to mute")
        return
@mute.error
async def mute_error(ctx, error):
    if isinstance(error, commands.CheckFailure):
        await ctx.send("You don't have the 'staff' role")  
like image 964
zTex Avatar asked May 16 '26 15:05

zTex


1 Answers

This specific line:

print("🔨 "+member+" was muted.")

Prints it in the terminal, or wherever you ran the command. Try await ctx.send Also, try using f-strings if you have version > 3.6 of Python. Also, your error is wrong.

@client.command()
@commands.has_role("staff")
async def mute(ctx, member: discord.Member):
    role = discord.utils.get(ctx.guild.roles, name="Muted")
    guild = ctx.guild
    if role not in guild.roles:
        perms = discord.Permissions(send_messages=False, speak=False)
        await guild.create_role(name="Muted", permissions=perms)
        await member.add_roles(role)
        await ctx.send(f"🔨{member} was muted.")
    else:
        await member.add_roles(role) 
        await ctx.send(f"🔨{member} was muted.")     

@mute.error
async def mute_error(ctx, error):
    if isinstance(error, commands.MissingRole):
        await ctx.send("You don't have the 'staff' role") 
@mute.error
async def mute_error(ctx, error):
    if isinstance(error, commands.BadArgument):
        await ctx.send("That is not a valid member") 
like image 69
AK - 10CA - Glenforest SS 2172 Avatar answered May 19 '26 03:05

AK - 10CA - Glenforest SS 2172



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!