Advertisement
Ohnezahn

Tempmute Command discord.py

Jul 19th, 2021 (edited)
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.93 KB | None | 0 0
  1. @client.command(aliases = ['tmute'])
  2. @commands.has_permissions(manage_roles = True)
  3. @commands.bot_has_guild_permissions(manage_roles = True)
  4. async def tempmute(ctx , member: discord.Member , time , * , reason=None):
  5.     global mute_role, perms
  6.     guild = ctx.guild
  7.     if discord.utils.get(ctx.guild.roles , name = "Muted"):
  8.         mute_role = discord.utils.get(guild.roles , name = "Muted" or "muted" or "Knast" or "Mute" or "mute")
  9.     else:
  10.         perms = discord.Permissions(send_messages = False , add_reactions = False , connect = False , speak = False)
  11.         await guild.create_role(name = "Muted" , permissions = perms)
  12.         mute_role = discord.utils.get(guild.roles , name = "Muted")
  13.         for channel in guild.text_channels:
  14.             await channel.set_permissions(mute_role , send_messages = False , add_reactions = False , connect = False , speak = False)
  15.  
  16.     if mute_role in member.roles:
  17.         await ctx.channel.send(f"{member} ist bereits gemuted")
  18.  
  19.     else:
  20.         if member.guild_permissions.administrator:
  21.             isadminembed = discord.Embed(title = "Error" ,
  22.                                          description = f"{ctx.author.mention} du kannst keine Server Administratoren muten!" ,
  23.                                          color = 0xff2200)
  24.             isadminembed.set_author(name = f"{client.user.name}#{client.user.discriminator}" ,
  25.                                     icon_url = f"{client.user.avatar_url}")
  26.             await ctx.channel.send(embed = isadminembed)
  27.         elif member.id == ctx.author.id:
  28.             isyourself = discord.Embed(title = "Fehler" ,
  29.                                        description = f"{ctx.author} du kannst dich nicht selber muten!" ,
  30.                                        color = 0xff2200)
  31.             isyourself.set_footer(text = f"User-ID: {ctx.author.id}")
  32.             isyourself.set_author(name = f"{ctx.author}" , icon_url = f"{ctx.author.avatar_url}")
  33.             isyourself.timestamp = datetime.datetime.utcnow()
  34.             await ctx.send(embed = isyourself)
  35.         else:
  36.             time_conversion = {"s": 1 , "m": 60 , "h": 3600 , "d": 86400 , "w": 604800 , "M": 2419200 , "y": 29030400}
  37.             mute_time = int(time[:-1]) * time_conversion[time[-1]]
  38.             for i in member.roles:
  39.                 try:
  40.                     await member.remove_roles(i)
  41.                     await member.add_roles(mute_role)
  42.                 except:
  43.                     pass
  44.             if reason is None:
  45.                 reason = "No Reason provided"
  46.             mutedembed = discord.Embed(title = "Tempmute" ,
  47.                                        description = f"{member} wurde von {ctx.author} gemuted\n\nZeit: {mute_time}s\nGrund: {reason}" ,
  48.                                        color = 0xff2200)
  49.             mutedembed.set_author(name = f"{client.user.name}#{client.user.discriminator}" ,
  50.                                   icon_url = f"{client.user.avatar_url}")
  51.             mutedembed.set_footer(text = f"User-ID: {member.id}")
  52.             await ctx.channel.send(embed = mutedembed)
  53.             await asyncio.sleep(mute_time)
  54.             for i in member.roles:
  55.                 try:
  56.                     await member.add_roles(i)
  57.                     await member.remove_roles(mute_role)
  58.                 except:
  59.                     pass
  60.             embed = discord.Embed(color = 0xff2200 , title = "Mute vorbei" ,
  61.                                   description = f"Der Mute von {member} ist vorbei!")
  62.             embed.set_footer(text = f"User-ID: {member.id}")
  63.             embed.set_author(name = f"{ctx.author}" , icon_url = f"{ctx.author.avatar_url}")
  64.             await ctx.send(embed = embed)
  65.  
  66.  
  67. @tempmute.error
  68. async def on_command_error(ctx , error):
  69.     if isinstance(ctx , commands.RoleNotFound):
  70.         raise error
  71.  
  72.  
  73. @tempmute.error
  74. async def on_command_error(ctx , error):
  75.     if isinstance(ctx , commands.CommandInvokeError):
  76.         raise error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement