Advertisement
iPlayG

vban update

Apr 25th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3.  
  4. class vban:
  5.     """Bans a user from entering any voice channel.
  6.    Commands:
  7.    [p]vban @ExampleUser#0123 {Time}
  8.    Created by iPlayᴳ#3282"""
  9.  
  10.     def __init__(self, bot):
  11.         self.bot = bot
  12.  
  13.     @commands.command(pass_context=True, no_pm=True)
  14.     async def vban(self, ctx, user: discord.Member):
  15.         """Bans a user from entering any voice channel. Example:
  16.        [p]vban @ExampleUser#0123 {Time}"""
  17.         server = ctx.message.server
  18.         vban = discord.utils.get(server.roles, name="VBanned")
  19.         try:
  20.             falure = False
  21.             for role in user.roles:
  22.                 if VBanned == role:
  23.                     failure == True
  24.                     break
  25.             if failure == False:
  26.                 await self.bot.add_roles(user, vban)
  27.                 await self.bot.say("Successfully voice banned <@{}>".format(user.id))
  28.             if failure == True:
  29.                 await self.bot.say("Sorry, I can't VBan someone who is already VBanned")
  30.         except:
  31.             await self.bot.say("Had an error. Please retry.")
  32.         channel = await self.bot.create_channel(server, 'bye', type=discord.ChannelType.voice)
  33.         await self.bot.move_member(user, channel)
  34.         await self.bot.delete_channel(channel)
  35.  
  36.     @commands.command(pass_context=True, no_pm=True)
  37.     async def unvban(self, ctx, *, user: discord.Member):
  38.         """Unbans a user that has been vbanned. Exmaple:
  39.        [p]unvban @ExampleUser#0123"""
  40.         server = ctx.message.server
  41.         vban = discord.utils.get(server.roles, name="VBanned")
  42.         success = False
  43.         for role in user.roles:
  44.             if VBanned == role:
  45.                 try:
  46.                     await self.bot.remove_roles(user, vban)
  47.                     await self.bot.say("Successfully un-voice banned <@{}>".format(user.id))
  48.                     success = True
  49.                     break
  50.         if success == False:
  51.             await self.bot.say("Can't Unvban some who isn't VBanned!")
  52.  
  53. def setup(bot):
  54.     bot.add_cog(vban(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement