Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js')
- const bot = new Discord.Client({ disableEveryone: true })
- const queue = new Map()
- const ytdl = require('ytdl-core')
- bot.login('NTU0NjkzODA2MjU2MDI5NzA3.D2ga1w.g6uMisx31L_qqk8yD3gYbO-B-VY')
- bot.on('ready', () => {
- console.log('BOT ONLINE')
- bot.user.setActivity('ANK BOT')
- })
- prefix = "!"
- bot.on('message', async function (msg) {
- if (!msg.content.startsWith(prefix)) return undefined
- let args = msg.content.split(' ')
- const serverQueue = queue.get(msg.guild.id)
- if (args[0].toLowerCase() === prefix + 'ping') {
- msg.channel.send("Pong!")
- }
- if (args[0].toLowerCase() === prefix + 'test') {
- msg.channel.send("Test").then(async function(message) {
- await message.react('⏮')
- await message.react('⏯')
- await message.react('⏭')
- const filter = function(reaction, user) {
- return ['⏮','⏯','⏭'].includes(reaction.emoji.name) && user.id != 554693806256029707
- }
- await message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }).then(async function(collected) {
- const reaction = collected.first()
- if (reaction.emoji.name === '⏮') {
- msg.channel.send("SKIP BACK")
- return undefined
- }
- if (reaction.emoji.name === '⏯') {
- msg.channel.send("PLAY PAUSE")
- return undefined
- }
- if (reaction.emoji.name === '⏭') {
- msg.channel.send("SKIP NEXT")
- return undefined
- }
- })
- })
- }
- if (args[0].toLowerCase() === prefix + 'play') {
- const channel = msg.member.voiceChannel
- if (!channel) {
- msg.channel.send(":x: | Tu dois rejoindre un canal vocal pour exécuter cette commande !")
- return undefined
- }
- const permissions = channel.permissionsFor(msg.client.user)
- if (!args[1]) {
- msg.channel.send(":x: | Merci de saisir un URL YouTube !")
- return undefined
- }
- if (!permissions.has('CONNECT')) {
- return msg.channel.send(":information_source: | Je n'ai pas les permissions de me connecter à ce canal")
- return undefined
- }
- if (!permissions.has('SPEAK')) {
- return msg.channel.send(":information_source: | Je ne peux pas parler dans ce canal")
- return undefined
- }
- try {
- await ytdl(args[1])
- } catch(error) {
- return msg.channel.send(":x: | Je ne peux pas lire cette vidéo")
- return undefined
- }
- const songInfo = await ytdl.getInfo(args[1])
- const song = {
- title: songInfo.title,
- url: songInfo.video_url
- }
- if (!serverQueue) {
- const queueConstruct = {
- textChannel: msg.channel,
- voiceChannel: channel,
- connection: null,
- songs: [],
- volume: 5,
- playing: true
- }
- queue.set(msg.guild.id, queueConstruct)
- queueConstruct.songs.push(song)
- try {
- var connection = await channel.join()
- queueConstruct.connection = connection
- play(msg.guild, queueConstruct.songs[0])
- } catch(error) {
- return msg.channel.send(":x: | Je ne peux pas me connecter à ce canal")
- }
- } else {
- serverQueue.songs.push(song)
- return msg.channel.send(`:white_check_mark: | **${song.title}** a été ajouté à la liste d'attente`)
- }
- }
- if (args[0].toLowerCase() === prefix + 'stop') {
- const client = msg.guild.voiceConnection
- const channel = msg.member.voiceChannel
- if (!client) {
- msg.channel.send("Je ne suis pas dans un canal vocal")
- } else {
- channel.leave()
- msg.react('👋')
- }
- }
- if (args[0].toLowerCase() === prefix + 'skip') {
- if (!msg.member.voiceChannel) return msg.channel.send(":x: | Tu dois rejoindre un canal vocal pour exécuter cette commande !")
- if (!serverQueue) return msg.channel.send('There is nothing playing that I could skip for you.')
- skip(msg.guild)
- }
- return undefined
- })
- function play(guild, song) {
- const serverQueue = queue.get(guild.id)
- if (!song) {
- serverQueue.voiceChannel.leave()
- queue.delete(guild.id)
- return;
- }
- console.log(serverQueue.songs)
- const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
- .on('end', reason => {
- if (reason === 'Stream is not generating quickly enough.') console.log('Fin chanson')
- else console.log(reason);
- const previous = serverQueue.songs[0]
- serverQueue.songs.shift();
- play(guild, serverQueue.songs[0])
- })
- .on('error', error => console.error(error))
- dispatcher.setVolumeLogarithmic(3 / 5)
- serverQueue.textChannel.send(`:musical_note: | Joue: **${song.title}**`).then(async function(message) {
- await message.react('⏮')
- await message.react('⏸')
- await message.react('⏭')
- const filter = function(reaction, user) {
- return ['⏮','⏸','⏭'].includes(reaction.emoji.name) && user.id != 554693806256029707
- }
- await message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }).then(async function(collected) {
- const reaction = collected.first()
- if (reaction.emoji.name === '⏮') {
- message.channel.send("SKIP BACK")
- return undefined
- }
- if (reaction.emoji.name === '⏸') {
- serverQueue.playing = false
- serverQueue.connection.dispatcher.pause()
- message.channel.send(":pause_button: | Musique en pause ! ").then(async function(message) {
- message.react('▶')
- const filter = function(reaction, user) {
- return ['▶'].includes(reaction.emoji.name) && user.id != 554693806256029707
- }
- await message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }).then(async function(collected) {
- const reaction = collected.first()
- if (reaction.emoji.name === '▶') {
- serverQueue.playing = true
- serverQueue.connection.dispatcher.resume()
- message.channel.send(':arrow_forward: | Play!')
- }
- })
- })
- return undefined
- }
- if (reaction.emoji.name === '⏭') {
- message.channel.send(":fast_forward: | Musique suivante")
- skip(guild)
- return undefined
- }
- })
- })
- }
- function skip(guild) {
- const serverQueue = queue.get(guild.id)
- serverQueue.connection.dispatcher.end()
- }
- async function playpause(message, guild) {
- const serverQueue = queue.get(guild.id)
- await message.react('⏮')
- await message.react('⏯')
- await message.react('⏭')
- const filter = function(reaction, user) {
- return ['⏮','⏯','⏭'].includes(reaction.emoji.name) && user.id != 554693806256029707
- }
- await message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }).then(async function(collected) {
- const reaction = collected.first()
- if (reaction.emoji.name === '⏮') {
- message.channel.send("SKIP BACK")
- return undefined
- }
- if (reaction.emoji.name === '⏯') {
- if (serverQueue.playing === true) {
- serverQueue.playing = false
- serverQueue.connection.dispatcher.pause()
- message.channel.send(":pause_button: | Musique en pause ! ")
- }
- if (serverQueue.playing ===false) {
- serverQueue.playing = true
- serverQueue.connection.dispatcher.resume()
- message.channel.send(':arrow_forward: | Play!')
- }
- return undefined
- }
- if (reaction.emoji.name === '⏭') {
- message.channel.send(":fast_forward: | Musique suivante")
- skip(guild)
- return undefined
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement