Reputation: 167
I am trying to make a mute command. The code below doesn't give any errors, but it doesn't work.
@client.command()
@commands.has_permissions(manage_messages=True)
async def mute(ctx, member : discord.Member) :
guild = ctx.guild
user = member
global mute_role
for role in guild.roles:
if role.name == "MUTED" :
if role in user.roles:
await ctx.send(f'**{user.name} is already muted!**')
else:
await member.add_roles(role)
await ctx.send(f"{member.mention} has been muted by {ctx.author} ")
for role in guild.roles:
if role.name == "MUTED" not in guild.roles:
mute_role = await guild.create_role(name="MUTED")
perms = discord.PermissionOverwrite(send_messages=False)
for channel in guild.text_channels :
await channel.set_permissions(mute_role, overwrite=perms)
if role.name == "MUTED" not in user.roles:
await member.add_roles(mute_role)
await ctx.send(f'{member.mention} has been muted by {ctx.author.mention}')
return
I have tried multiple methods and "played around" with the variables but I have not managed to make a functional command. I would also like to make a timed mute command, but first I need to make this work. I have searched for other mute commands on StackOverflow but I could not find anything functional or decent. Also, if I am able to make this work, how would I go about making an unmute command too?
Upvotes: 1
Views: 2043
Reputation: 13
Well I know it is probably too late, but here is my mute command:
@client.command()
@commands.has_permissions(kick_members=True)
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("Successfully created Muted role and assigned it to mentioned user.")
else:
await member.add_roles(role)
await ctx.send(f"Successfully muted ({member})")
@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")
I, too, need an unmute command.
Upvotes: 1