Spotify support added

This commit is contained in:
killer069
2021-09-05 18:50:57 +05:30
parent 2a84dceda6
commit 4179557fde
14 changed files with 609 additions and 203 deletions

View File

@@ -0,0 +1,48 @@
const discord = require('discord.js')
const { Intents } = require('discord.js')
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
const play = require('play-dl')
const client = new discord.Client({ intents : [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.DIRECT_MESSAGES] , partials : ['CHANNEL', 'MESSAGE']})
const token = '< YOUR BOT TOKEN >'
const COOKIE = '< YOUR COOKIES >'
client.on('messageCreate', async message => {
if(message.content.startsWith('!play')){
if(!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
const connection = joinVoiceChannel({
channelId : message.member.voice.channel.id,
guildId : message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
})
let args = message.content.split('play ')[1].split(' ')[0]
let stream = await play.stream(args, COOKIE)
/*
OR if you want to get info about youtube link and then stream it
let yt_info = await play.video_info(args, COOKIE)
console.log(yt_info.video_details.title)
let stream = await play.stream_from_info(yt_info)
*/
let resource = createAudioResource(stream.stream, {
inputType : stream.type
})
let player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play
}
})
player.play(resource)
connection.subscribe(player)
}
})
client.on('ready', () => {
console.log(`We have logged in as ${client.user.tag}!`)
})
client.login(token);

View File

@@ -0,0 +1,40 @@
const discord = require('discord.js')
const { Intents } = require('discord.js')
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
const play = require('play-dl')
const client = new discord.Client({ intents : [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.DIRECT_MESSAGES] , partials : ['CHANNEL', 'MESSAGE']})
const token = '< YOUR BOT TOKEN >'
client.on('messageCreate', async message => {
if(message.content.startsWith('!play')){
if(!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
const connection = joinVoiceChannel({
channelId : message.member.voice.channel.id,
guildId : message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
})
let args = message.content.split('play')[1]
let yt_info = await play.search(args, { limit : 1 })
let stream = await play.stream(yt_info[0].url)
let resource = createAudioResource(stream.stream, {
inputType : stream.type
})
let player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play
}
})
player.play(resource)
connection.subscribe(player)
}
})
client.on('ready', () => {
console.log(`We have logged in as ${client.user.tag}!`)
})
client.login(token);

View File

@@ -0,0 +1,47 @@
const discord = require('discord.js')
const { Intents } = require('discord.js')
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
const play = require('play-dl')
const client = new discord.Client({ intents : [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.DIRECT_MESSAGES] , partials : ['CHANNEL', 'MESSAGE']})
const token = '< YOUR BOT TOKEN >'
client.on('messageCreate', async message => {
if(message.content.startsWith('!play')){
if(!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
const connection = joinVoiceChannel({
channelId : message.member.voice.channel.id,
guildId : message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
})
let args = message.content.split('play ')[1].split(' ')[0]
let stream = await play.stream(args)
/*
OR if you want to get info about youtube link and then stream it
let yt_info = await play.video_info(args)
console.log(yt_info.video_details.title)
let stream = await play.stream_from_info(yt_info)
*/
let resource = createAudioResource(stream.stream, {
inputType : stream.type
})
let player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play
}
})
player.play(resource)
connection.subscribe(player)
}
})
client.on('ready', () => {
console.log(`We have logged in as ${client.user.tag}!`)
})
client.login(token);