Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.08 KB | None | 0 0
  1. ----------------
  2. CHAT COMMANDS
  3. ----------------
  4. import discord
  5. from discord.ext import commands
  6. from discord.ext.commands import Bot
  7. import asyncio
  8.  
  9. bot = commands.Bot(command_prefix='.')
  10. startup_extensions = ["Music"]
  11.  
  12. print (discord.__version__)
  13. @bot.event
  14. async def on_ready():
  15. print("Ready when you are xd")
  16. @bot.command(pass_context=True)
  17. async def bc(ctx):
  18. await bot.say("This bot was created by Curium Gaming, make sure to dm him if there is any errors.")
  19. print ("user has asked for ur link")
  20. @bot.command(pass_context=True)
  21. async def mc(ctx):
  22. await bot.say("Music commands are listed here: @LightOfTheShadow help.")
  23. print ("user has asked for cmds")
  24.  
  25.  
  26. @bot.command(pass_context=True)
  27. async def info(ctx, user: discord.Member):
  28. embed = discord.Embed(title="{}'s info".format(user.name), description="Here's what I could find.", color=0x00ff00)
  29. embed.add_field(name="Name", value=user.name, inline=True)
  30. embed.add_field(name="ID", value=user.id, inline=True)
  31. embed.add_field(name="Status", value=user.status, inline=True)
  32. embed.add_field(name="Highest role", value=user.top_role)
  33. embed.add_field(name="Joined", value=user.joined_at)
  34. embed.set_thumbnail(url=user.avatar_url)
  35. await bot.say(embed=embed)
  36. @bot.command(pass_context=True)
  37. async def serverinfo(ctx):
  38. embed = discord.Embed(name="{}'s info".format(ctx.message.server.name), description="Here's what I could find.", color=0x00ff00)
  39. embed.set_author(name="Ben Mascotts")
  40. embed.add_field(name="Name", value=ctx.message.server.name, inline=True)
  41. embed.add_field(name="ID", value=ctx.message.server.id, inline=True)
  42. embed.add_field(name="Roles", value=len(ctx.message.server.roles), inline=True)
  43. embed.add_field(name="Members", value=len(ctx.message.server.members))
  44. embed.set_thumbnail(url=ctx.message.server.icon_url)
  45. await bot.say(embed=embed)
  46.  
  47. @bot.command(pass_context=True)
  48. @commands.has_role("😂👌 Friends")
  49. async def kick(ctx, user: discord.Member):
  50. await bot.say(":boot: Cya, {}. Ya loser!".format(user.name))
  51. await bot.kick(user)
  52.  
  53. @bot.command(pass_context=True)
  54. async def embed(ctx):
  55. embed = discord.Embed(title="Are you subbed to shadow scyther?", description="Are you subbed to Ben Mascotts?", color=0xF200FF)
  56. embed.set_footer(text="https://www.youtube.com/c/ShadowScyther")
  57. embed.set_author(name="Ben Mascotts is best ")
  58. embed.add_field(name="Defiantl is a good pvper", value="yep he is", inline=True)
  59. await bot.say(embed=embed) print("I am running on " + bot.user.name)
  60. print("With the ID: " + bot.user.id)
  61. @bot.command(pass_context=True)
  62. async def yt(ctx):help
  63. await bot.say("@everyone Subscribe to Shadow Scyther, https://www.youtube.com/c/ShadowScyther. ")
  64. print ("user has asked for shadows link")
  65. @bot.command(pass_context=True)
  66. async def ls(ctx):
  67. await bot.say("Last Livestream was: https://www.youtube.com/watch?v=c8A8SG6wiwk make sure you go watch it.")
  68. print ("user has asked for livestream link")
  69. @bot.command(pass_context=True)
  70. async def bc(ctx):
  71. await bot.say("This bot was created by Curium Gaming, make sure to dm him if there is any errors.")
  72. print ("user has asked for ur link")
  73. @bot.command(pass_context=True)
  74. async def mc(ctx):
  75. await bot.say("Music commands are listed here: @LightOfTheShadow help.")
  76. print ("user has asked for cmds")
  77.  
  78.  
  79. @bot.command(pass_context=True)
  80. async def info(ctx, user: discord.Member):
  81. embed = discord.Embed(title="{}'s info".format(user.name), description="Here's what I could find.", color=0x00ff00)
  82. embed.add_field(name="Name", value=user.name, inline=True)
  83. embed.add_field(name="ID", value=user.id, inline=True)
  84. embed.add_field(name="Status", value=user.status, inline=True)
  85. embed.add_field(name="Highest role", value=user.top_role)
  86. embed.add_field(name="Joined", value=user.joined_at)
  87. embed.set_thumbnail(url=user.avatar_url)
  88. await bot.say(embed=embed)
  89. @bot.command(pass_context=True)
  90. async def serverinfo(ctx):
  91. embed = discord.Embed(name="{}'s info".format(ctx.message.server.name), description="Here's what I could find.", color=0x00ff00)
  92. embed.set_author(name="Ben Mascotts")
  93. embed.add_field(name="Name", value=ctx.message.server.name, inline=True)
  94. embed.add_field(name="ID", value=ctx.message.server.id, inline=True)
  95. embed.add_field(name="Roles", value=len(ctx.message.server.roles), inline=True)
  96. embed.add_field(name="Members", value=len(ctx.message.server.members))
  97. embed.set_thumbnail(url=ctx.message.server.icon_url)
  98. await bot.say(embed=embed)
  99.  
  100. @bot.command(pass_context=True)
  101. @commands.has_role("😂👌 Friends")
  102. async def kick(ctx, user: discord.Member):
  103. await bot.say(":boot: Cya, {}. Ya loser!".format(user.name))
  104. await bot.kick(user)
  105.  
  106. @bot.command(pass_context=True)
  107. async def embed(ctx):
  108. embed = discord.Embed(title="Are you subbed to shadow scyther?", description="Are you subbed to Ben Mascotts?", color=0xF200FF)
  109. embed.set_footer(text="https://www.youtube.com/c/ShadowScyther")
  110. embed.set_author(name="Ben Mascotts is best ")
  111. embed.add_field(name="Defiantl is a good pvper", value="yep he is", inline=True)
  112. await bot.say(embed=embed)
  113. ----------------
  114. MUSIC COMMANDS
  115. ----------------
  116. import asyncio
  117. import discord
  118. from discord.ext import commands
  119.  
  120. if not discord.opus.is_loaded():
  121. # the 'opus' library here is opus.dll on windows
  122. # or libopus.so on linux in the current directory
  123. # you should replace this with the location the
  124. # opus library is located in and with the proper filename.
  125. # note that on windows this DLL is automatically provided for you
  126. discord.opus.load_opus('opus')
  127.  
  128. class VoiceEntry:
  129. def __init__(self, message, player):
  130. self.requester = message.author
  131. self.channel = message.channel
  132. self.player = player
  133.  
  134. def __str__(self):
  135. fmt = '*{0.title}* uploaded by {0.uploader} and requested by {1.display_name}'
  136. duration = self.player.duration
  137. if duration:
  138. fmt = fmt + ' [length: {0[0]}m {0[1]}s]'.format(divmod(duration, 60))
  139. return fmt.format(self.player, self.requester)
  140.  
  141. class VoiceState:
  142. def __init__(self, bot):
  143. self.current = None
  144. self.voice = None
  145. self.bot = bot
  146. self.play_next_song = asyncio.Event()
  147. self.songs = asyncio.Queue()
  148. self.skip_votes = set() # a set of user_ids that voted
  149. self.audio_player = self.bot.loop.create_task(self.audio_player_task())
  150.  
  151. def is_playing(self):
  152. if self.voice is None or self.current is None:
  153. return False
  154.  
  155. player = self.current.player
  156. return not player.is_done()
  157.  
  158. @property
  159. def player(self):
  160. return self.current.player
  161.  
  162. def skip(self):
  163. self.skip_votes.clear()
  164. if self.is_playing():
  165. self.player.stop()
  166.  
  167. def toggle_next(self):
  168. self.bot.loop.call_soon_threadsafe(self.play_next_song.set)
  169.  
  170. async def audio_player_task(self):
  171. while True:
  172. self.play_next_song.clear()
  173. self.current = await self.songs.get()
  174. await self.bot.send_message(self.current.channel, 'Now playing ' + str(self.current))
  175. self.current.player.start()
  176. await self.play_next_song.wait()
  177.  
  178. class Music:
  179. """Voice related commands.
  180.  
  181. Works in multiple servers at once.
  182. """
  183. def __init__(self, bot):
  184. self.bot = bot
  185. self.voice_states = {}
  186.  
  187. def get_voice_state(self, server):
  188. state = self.voice_states.get(server.id)
  189. if state is None:
  190. state = VoiceState(self.bot)
  191. self.voice_states[server.id] = state
  192.  
  193. return state
  194.  
  195. async def create_voice_client(self, channel):
  196. voice = await self.bot.join_voice_channel(channel)
  197. state = self.get_voice_state(channel.server)
  198. state.voice = voice
  199.  
  200. def __unload(self):
  201. for state in self.voice_states.values():
  202. try:
  203. state.audio_player.cancel()
  204. if state.voice:
  205. self.bot.loop.create_task(state.voice.disconnect())
  206. except:
  207. pass
  208.  
  209. @commands.command(pass_context=True, no_pm=True)
  210. async def join(self, ctx, *, channel : discord.Channel):
  211. """Joins a voice channel."""
  212. try:
  213. await self.create_voice_client(channel)
  214. except discord.ClientException:
  215. await self.bot.say('Already in a voice channel...')
  216. except discord.InvalidArgument:
  217. await self.bot.say('This is not a voice channel...')
  218. else:
  219. await self.bot.say('Ready to play audio in ' + channel.name)
  220.  
  221. @commands.command(pass_context=True, no_pm=True)
  222. async def summon(self, ctx):
  223. """Summons the bot to join your voice channel."""
  224. summoned_channel = ctx.message.author.voice_channel
  225. if summoned_channel is None:
  226. await self.bot.say('You are not in a voice channel.')
  227. return False
  228.  
  229. state = self.get_voice_state(ctx.message.server)
  230. if state.voice is None:
  231. state.voice = await self.bot.join_voice_channel(summoned_channel)
  232. else:
  233. await state.voice.move_to(summoned_channel)
  234.  
  235. return True
  236.  
  237. @commands.command(pass_context=True, no_pm=True)
  238. async def play(self, ctx, *, song : str):
  239. """Plays a song.
  240.  
  241. If there is a song currently in the queue, then it is
  242. queued until the next song is done playing.
  243.  
  244. This command automatically searches as well from YouTube.
  245. The list of supported sites can be found here:
  246. https://rg3.github.io/youtube-dl/supportedsites.html
  247. """
  248. state = self.get_voice_state(ctx.message.server)
  249. opts = {
  250. 'default_search': 'auto',
  251. 'quiet': True,
  252. }
  253.  
  254. if state.voice is None:
  255. success = await ctx.invoke(self.summon)
  256. if not success:
  257. return
  258.  
  259. try:
  260. player = await state.voice.create_ytdl_player(song, ytdl_options=opts, after=state.toggle_next)
  261. except Exception as e:
  262. fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
  263. await self.bot.send_message(ctx.message.channel, fmt.format(type(e).__name__, e))
  264. else:
  265. player.volume = 0.6
  266. entry = VoiceEntry(ctx.message, player)
  267. await self.bot.say('Enqueued ' + str(entry))
  268. await state.songs.put(entry)
  269.  
  270. @commands.command(pass_context=True, no_pm=True)
  271. async def volume(self, ctx, value : int):
  272. """Sets the volume of the currently playing song."""
  273.  
  274. state = self.get_voice_state(ctx.message.server)
  275. if state.is_playing():
  276. player = state.player
  277. player.volume = value / 100
  278. await self.bot.say('Set the volume to {:.0%}'.format(player.volume))
  279.  
  280. @commands.command(pass_context=True, no_pm=True)
  281. async def pause(self, ctx):
  282. """Pauses the currently played song."""
  283. state = self.get_voice_state(ctx.message.server)
  284. if state.is_playing():
  285. player = state.player
  286. player.pause()
  287.  
  288. @commands.command(pass_context=True, no_pm=True)
  289. async def resume(self, ctx):
  290. """Resumes the currently played song."""
  291. state = self.get_voice_state(ctx.message.server)
  292. if state.is_playing():
  293. player = state.player
  294. player.resume()
  295.  
  296. @commands.command(pass_context=True, no_pm=True)
  297. async def stop(self, ctx):
  298. """Stops playing audio and leaves the voice channel.
  299.  
  300. This also clears the queue.
  301. """
  302. server = ctx.message.server
  303. state = self.get_voice_state(server)
  304.  
  305. if state.is_playing():
  306. player = state.player
  307. player.stop()
  308.  
  309. try:
  310. state.audio_player.cancel()
  311. del self.voice_states[server.id]
  312. await state.voice.disconnect()
  313. except:
  314. pass
  315.  
  316. @commands.command(pass_context=True, no_pm=True)
  317. async def skip(self, ctx):
  318. """Vote to skip a song. The song requester can automatically skip.
  319.  
  320. 3 skip votes are needed for the song to be skipped.
  321. """
  322.  
  323. state = self.get_voice_state(ctx.message.server)
  324. if not state.is_playing():
  325. await self.bot.say('Not playing any music right now...')
  326. return
  327.  
  328. voter = ctx.message.author
  329. if voter == state.current.requester:
  330. await self.bot.say('Requester requested skipping song...')
  331. state.skip()
  332. elif voter.id not in state.skip_votes:
  333. state.skip_votes.add(voter.id)
  334. total_votes = len(state.skip_votes)
  335. if total_votes >= 3:
  336. await self.bot.say('Skip vote passed, skipping song...')
  337. state.skip()
  338. else:
  339. await self.bot.say('Skip vote added, currently at [{}/3]'.format(total_votes))
  340. else:
  341. await self.bot.say('You have already voted to skip this song.')
  342.  
  343. @commands.command(pass_context=True, no_pm=True)
  344. async def playing(self, ctx):
  345. """Shows info about the currently played song."""
  346.  
  347. state = self.get_voice_state(ctx.message.server)
  348. if state.current is None:
  349. await self.bot.say('Not playing anything.')
  350. else:
  351. skip_count = len(state.skip_votes)
  352. await self.bot.say('Now playing {} [skips: {}/3]'.format(state.current, skip_count))
  353.  
  354. bot = commands.Bot(command_prefix=commands.when_mentioned_or('$'), description="Help options for LightOfTheShadow aka Shadow Scyther's Private Discord bot")
  355. bot.add_cog(Music(bot))
  356.  
  357. @bot.event
  358. async def on_ready():
  359. print('Logged in as:\n{0} (ID: {0.id})'.format(bot.user))
  360. ---------------------------------
  361. NOTE: I CUT OFF THE TOKEN SO THEN
  362. THE BOT CANNOT BE HACKED
  363. ---------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement