Created
June 12, 2021 09:28
-
-
Save asrvd/9461fe01f795462f013faf83a293ee1a to your computer and use it in GitHub Desktop.
Discord bot timed mute command for discord.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Having a Muted role in the server is necessary. If the server doesn't have a Muted role you need to make it and then specify it's permissions. | |
import discord | |
from discord.ext import commands | |
import asyncio | |
@client.command | |
@client.has_permissions(kick_members=True) | |
async def mute(ctx, member: discord.Member=None, time = None, *, reason = None): | |
muted_role = discord.utils.get(ctx.guild.roles, name="Muted") | |
time_convert = {"s": 1, "m": 60, "h":3600, "d":86400} | |
if member == None: | |
await ctx.send("You must mention a user!") | |
elif time == None: | |
await ctx.send("You must mention a time!") | |
elif reason == None: | |
reason = "None" | |
tempmute= int(time[:-1]) * time_convert[time[-1]] | |
muted_embed = discord.Embed(title="User muted!", description=f"{member.mention} is muted for {time} Reason: {reason}.", color=0x13fc03) | |
await ctx.send(embed=muted_embed) | |
await member.add_roles(muted_role) | |
await asyncio.sleep(tempmute) | |
unmute_embed = discord.Embed(title="User unmuted!", description=f"{member.mention} is unmuted now.", color=0x13fc03) | |
await ctx.send(embed=unmute_embed) | |
await member.remove_roles(muted_role) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment