Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. import discord
  2. import asyncio
  3. from discord.voice_client import VoiceClient
  4. from discord.ext.commands import Bot
  5. from discord.ext import commands
  6.  
  7. Client = discord.Client()
  8. bot_prefix= "."
  9. client = commands.Bot(command_prefix=bot_prefix)
  10. vc_clients = {}
  11.  
  12. @client.event
  13. async def on_ready():
  14. print("Bot Online!")
  15. print("Name: {}".format(client.user.name))
  16. print("ID: {}".format(client.user.id))
  17. await client.change_presence(game=discord.Game(name='type .help'))
  18.  
  19. @client.command(pass_context=True)
  20. async def ping(ctx):
  21. await client.say("Server is responsive!")
  22.  
  23. #Allows the bot to connect:
  24. @client.command(pass_context=True)
  25. async def connect(ctx):
  26. if client.is_voice_connected(ctx.message.server):
  27. return await client.say("I am already connected to a voice channel. Do not disconnect me if I am in use!")
  28. author = ctx.message.author
  29. voice_channel = author.voice_channel
  30. vc = await client.join_voice_channel(voice_channel)
  31.  
  32. #Allows the bot to disconnect:
  33. @client.command(pass_context = True)
  34. async def disconnect(ctx):
  35. if ctx.message.server.id not in vc_clients:
  36. return await client.say("I am not in any voice channel!")
  37.  
  38. vc_clients[ctx.message.server.id][1].stop()
  39. await vc_clients[ctx.message.server.id][0].disconnect()
  40. return await client.say("Disconnected from voice channel!")
  41.  
  42. #Allows the bot to play music:
  43. @client.command(pass_context = True)
  44. async def play(ctx, url):
  45. message = ctx.message
  46. print(url);
  47.  
  48. if ctx.message.server.id not in vc_clients:
  49. try:
  50. vc = await client.join_voice_channel(message.author.voice_channel)
  51. vc_clients[message.server.id] = [vc]
  52.  
  53. except Exception as e:
  54. print(e)
  55. return await client.say("You are not in any voice channel.")
  56.  
  57. try:
  58. mg = await client.say("Searching...")
  59. player = await vc_clients[ctx.message.server.id][0].create_ytdl_player(url)
  60. vc_clients[message.server.id].append(player)
  61. player.start()
  62.  
  63. except Exception as e:
  64. return await client.say("ERROR: `%s"%e)
  65.  
  66. embed = discord.Embed(title = "Now playing :musical_note:", description = str(player.title), color = 0x0000FF)
  67. embed.add_field(name = "Duration (in seconds)", value = str(player.duration))
  68. embed.add_field(name = "Requested by", value = str(message.author))
  69. await client.delete_message(mg)
  70. return await client.say(embed = embed)
  71.  
  72. #Allows the bot to clear chat (up to fourteen days.)
  73. @client.command(pass_context = True)
  74. async def clear(ctx, number):
  75. mgs = []
  76. number = int(number) #Converting the amount of messages to delete to an integer
  77. async for x in client.logs_from(ctx.message.channel, limit = number):
  78. mgs.append(x)
  79. await client.delete_messages(mgs)
  80. await client.say(str(number) + " messages cleared!")
  81.  
  82. #Gets a list of all banned users on the server:
  83. @client.command(pass_context = True)
  84. async def getbans(ctx):
  85. x = await client.get_bans(ctx.message.server)
  86. x = '\n'.join([y.name for y in x])
  87. embed = discord.Embed(title = "List of Banned Members", description = x, color = 0xFFFFF)
  88. return await client.say(embed = embed)
  89. #General commands:
  90.  
  91. @client.command(pass_context = True)
  92. async def purpose(*args):
  93. return await client.say("I am a very complex AI that was designed to serve my owner.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement