Advertisement
Guest User

Untitled

a guest
May 25th, 2019
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.53 KB | None | 0 0
  1. const Discord = require('discord.js')
  2. const bot = new Discord.Client({ disableEveryone: true })
  3. const queue = new Map()
  4. const ytdl = require('ytdl-core')
  5. bot.login('NTU0NjkzODA2MjU2MDI5NzA3.D2ga1w.g6uMisx31L_qqk8yD3gYbO-B-VY')
  6. bot.on('ready', () => {
  7. console.log('BOT ONLINE')
  8. bot.user.setActivity('ANK BOT')
  9. })
  10.  
  11. prefix = "!"
  12.  
  13. bot.on('message', async function (msg) {
  14. if (!msg.content.startsWith(prefix)) return undefined
  15. let args = msg.content.split(' ')
  16. const serverQueue = queue.get(msg.guild.id)
  17. if (args[0].toLowerCase() === prefix + 'ping') {
  18. msg.channel.send("Pong!")
  19. }
  20. if (args[0].toLowerCase() === prefix + 'test') {
  21. msg.channel.send("Test").then(async function(message) {
  22. await message.react('⏮')
  23. await message.react('⏯')
  24. await message.react('⏭')
  25. const filter = function(reaction, user) {
  26. return ['⏮','⏯','⏭'].includes(reaction.emoji.name) && user.id != 554693806256029707
  27. }
  28. await message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }).then(async function(collected) {
  29. const reaction = collected.first()
  30. if (reaction.emoji.name === '⏮') {
  31. msg.channel.send("SKIP BACK")
  32. return undefined
  33. }
  34. if (reaction.emoji.name === '⏯') {
  35. msg.channel.send("PLAY PAUSE")
  36. return undefined
  37. }
  38. if (reaction.emoji.name === '⏭') {
  39. msg.channel.send("SKIP NEXT")
  40. return undefined
  41. }
  42. })
  43. })
  44. }
  45. if (args[0].toLowerCase() === prefix + 'play') {
  46. const channel = msg.member.voiceChannel
  47. if (!channel) {
  48. msg.channel.send(":x: | Tu dois rejoindre un canal vocal pour exécuter cette commande !")
  49. return undefined
  50. }
  51. const permissions = channel.permissionsFor(msg.client.user)
  52. if (!args[1]) {
  53. msg.channel.send(":x: | Merci de saisir un URL YouTube !")
  54. return undefined
  55. }
  56. if (!permissions.has('CONNECT')) {
  57. return msg.channel.send(":information_source: | Je n'ai pas les permissions de me connecter à ce canal")
  58. return undefined
  59. }
  60. if (!permissions.has('SPEAK')) {
  61. return msg.channel.send(":information_source: | Je ne peux pas parler dans ce canal")
  62. return undefined
  63. }
  64. try {
  65. await ytdl(args[1])
  66. } catch(error) {
  67. return msg.channel.send(":x: | Je ne peux pas lire cette vidéo")
  68. return undefined
  69. }
  70. const songInfo = await ytdl.getInfo(args[1])
  71. const song = {
  72. title: songInfo.title,
  73. url: songInfo.video_url
  74. }
  75.  
  76. if (!serverQueue) {
  77. const queueConstruct = {
  78. textChannel: msg.channel,
  79. voiceChannel: channel,
  80. connection: null,
  81. songs: [],
  82. volume: 5,
  83. playing: true
  84. }
  85. queue.set(msg.guild.id, queueConstruct)
  86. queueConstruct.songs.push(song)
  87. try {
  88. var connection = await channel.join()
  89. queueConstruct.connection = connection
  90. play(msg.guild, queueConstruct.songs[0])
  91. } catch(error) {
  92. return msg.channel.send(":x: | Je ne peux pas me connecter à ce canal")
  93. }
  94. } else {
  95. serverQueue.songs.push(song)
  96. return msg.channel.send(`:white_check_mark: | **${song.title}** a été ajouté à la liste d'attente`)
  97. }
  98. }
  99. if (args[0].toLowerCase() === prefix + 'stop') {
  100. const client = msg.guild.voiceConnection
  101. const channel = msg.member.voiceChannel
  102. if (!client) {
  103. msg.channel.send("Je ne suis pas dans un canal vocal")
  104. } else {
  105. channel.leave()
  106. msg.react('👋')
  107. }
  108. }
  109. if (args[0].toLowerCase() === prefix + 'skip') {
  110. if (!msg.member.voiceChannel) return msg.channel.send(":x: | Tu dois rejoindre un canal vocal pour exécuter cette commande !")
  111. if (!serverQueue) return msg.channel.send('There is nothing playing that I could skip for you.')
  112. skip(msg.guild)
  113. }
  114. return undefined
  115. })
  116.  
  117.  
  118. function play(guild, song) {
  119. const serverQueue = queue.get(guild.id)
  120. if (!song) {
  121. serverQueue.voiceChannel.leave()
  122. queue.delete(guild.id)
  123. return;
  124. }
  125. console.log(serverQueue.songs)
  126.  
  127. const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
  128. .on('end', reason => {
  129. if (reason === 'Stream is not generating quickly enough.') console.log('Fin chanson')
  130. else console.log(reason);
  131. const previous = serverQueue.songs[0]
  132. serverQueue.songs.shift();
  133. play(guild, serverQueue.songs[0])
  134. })
  135. .on('error', error => console.error(error))
  136. dispatcher.setVolumeLogarithmic(3 / 5)
  137.  
  138. serverQueue.textChannel.send(`:musical_note: | Joue: **${song.title}**`).then(async function(message) {
  139. await message.react('⏮')
  140. await message.react('⏸')
  141. await message.react('⏭')
  142. const filter = function(reaction, user) {
  143. return ['⏮','⏸','⏭'].includes(reaction.emoji.name) && user.id != 554693806256029707
  144. }
  145. await message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }).then(async function(collected) {
  146. const reaction = collected.first()
  147. if (reaction.emoji.name === '⏮') {
  148. message.channel.send("SKIP BACK")
  149. return undefined
  150. }
  151. if (reaction.emoji.name === '⏸') {
  152. serverQueue.playing = false
  153. serverQueue.connection.dispatcher.pause()
  154. message.channel.send(":pause_button: | Musique en pause ! ").then(async function(message) {
  155. message.react('▶')
  156. const filter = function(reaction, user) {
  157. return ['▶'].includes(reaction.emoji.name) && user.id != 554693806256029707
  158. }
  159. await message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }).then(async function(collected) {
  160. const reaction = collected.first()
  161. if (reaction.emoji.name === '▶') {
  162. serverQueue.playing = true
  163. serverQueue.connection.dispatcher.resume()
  164. message.channel.send(':arrow_forward: | Play!')
  165. }
  166. })
  167. })
  168. return undefined
  169. }
  170. if (reaction.emoji.name === '⏭') {
  171. message.channel.send(":fast_forward: | Musique suivante")
  172. skip(guild)
  173. return undefined
  174. }
  175. })
  176. })
  177. }
  178.  
  179. function skip(guild) {
  180. const serverQueue = queue.get(guild.id)
  181. serverQueue.connection.dispatcher.end()
  182. }
  183.  
  184. async function playpause(message, guild) {
  185. const serverQueue = queue.get(guild.id)
  186. await message.react('⏮')
  187. await message.react('⏯')
  188. await message.react('⏭')
  189. const filter = function(reaction, user) {
  190. return ['⏮','⏯','⏭'].includes(reaction.emoji.name) && user.id != 554693806256029707
  191. }
  192. await message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }).then(async function(collected) {
  193. const reaction = collected.first()
  194. if (reaction.emoji.name === '⏮') {
  195. message.channel.send("SKIP BACK")
  196. return undefined
  197. }
  198. if (reaction.emoji.name === '⏯') {
  199. if (serverQueue.playing === true) {
  200. serverQueue.playing = false
  201. serverQueue.connection.dispatcher.pause()
  202. message.channel.send(":pause_button: | Musique en pause ! ")
  203. }
  204. if (serverQueue.playing ===false) {
  205. serverQueue.playing = true
  206. serverQueue.connection.dispatcher.resume()
  207. message.channel.send(':arrow_forward: | Play!')
  208. }
  209. return undefined
  210. }
  211. if (reaction.emoji.name === '⏭') {
  212. message.channel.send(":fast_forward: | Musique suivante")
  213. skip(guild)
  214. return undefined
  215. }
  216. })
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement