Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

discord.py

@bot.command()
@has_permissions(administrator=True)
async def mute(ctx, member: nextcord.Member=None, time=None, *, reason="No reason specified"):
    if member is None:
        embed = nextcord.Embed(title="Command: !mute",
                               description=f"**Description:** Mute a member, optional reason
**Cooldown:** 3 Seconds",
                               color=0x2596be)
        embed.add_field(name="Usage:", value=f"!mute [user] [time] (reason)", inline=False)
        embed.add_field(name="Example", value=f"!mute bean 5m Squishing Small ants", inline=False)
        await ctx.send(embed=embed)
    if time is None:
        embed = nextcord.Embed(title="Command: !mute",
                               description=f"**Description:** Mute a member, optional reason
**Cooldown:** 3 Seconds",
                               color=0x2596be)
        embed.add_field(name="Usage:", value=f"!mute [user] [time] (reason)", inline=False)
        embed.add_field(name="Example", value=f"!mute bean 5m Squishing Small ants", inline=False)
        await ctx.send(embed=embed)
    else:
        desctime = time
        guild = ctx.guild
        mutedRole = nextcord.utils.get(guild.roles, name="Muted")
        time_convert = {"s":1, "m":60, "h":3600, "d":86400, "w":604800, "mo":31536000}
        tempmute = int(time[0]) * time_convert[time[-1]]
        if not mutedRole:
            embed = nextcord.Embed(title="Setup Muted Role", description="No Muted role was found, please create one!")
            embed.set_footer(text="Due to issues I can't create one myself...")
            await ctx.send(embed=embed)
        else:
            embed = nextcord.Embed(title="Muted", description=f"{member.mention} was muted for {desctime}")
            embed.set_image(url="https://c.tenor.com/l1yJ91orR_kAAAAd/yt-battles-youre-muted.gif")
            embed.add_field(name="Reason", value=reason, inline=False)
            await ctx.send(embed=embed)
            embed = nextcord.Embed(title="Muted", description=f"You were muted in {ctx.guild.name} for {desctime}")
            embed.add_field(name="Reason", value=reason)
            embed.set_image(url="https://c.tenor.com/l1yJ91orR_kAAAAd/yt-battles-youre-muted.gif")
            embed.add_field(name="Times", value="s = seconds
m = minutes
h = hours
d = days
w = weeks
mo = months")
            await member.send(embed=embed)
            await member.add_roles(mutedRole, reason=reason)
            await asyncio.sleep(tempmute)
            embed = nextcord.Embed(title="Unmuted", description=f"You were unmuted in {ctx.guild.name}")
            await member.send(embed=embed)
            embed = nextcord.Embed(title="Unmuted", description=f"Unmuted {member.mention}")
            await ctx.send(embed=embed)
            await member.remove_roles(mutedRole)

@bot.command()
@has_permissions(administrator=True)
async def unmute(ctx, member: nextcord.Member):
    mutedRole = nextcord.utils.get(member.roles, name="Muted")
    if not mutedRole:
        embed = nextcord.Embed(title="Can't unmute", description="This user is not muted!")
        embed.set_footer(text="Did you mean !mute?")
        await ctx.send(embed=embed)
    else:
        embed = nextcord.Embed(title="Unmuted", description=f"You were unmuted in {ctx.guild.name}")
        await member.send(embed=embed)
        embed = nextcord.Embed(title="Unmuted", description=f"Unmuted {member.mention}")
        await ctx.send(embed=embed)
        await member.remove_roles(mutedRole)
Source by pypi.org #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
4+6 =