mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-30 20:24:25 +00:00
Spotify support added
This commit is contained in:
42
examples/Spotify/play.js
Normal file
42
examples/Spotify/play.js
Normal file
@@ -0,0 +1,42 @@
|
||||
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 sp_data = await play.spotify(args) // This will get spotify data from the url [ I used track url, make sure to make a logic for playlist, album ]
|
||||
let searched = await play.search(`${sp_data.name}`, { limit : 1 }) // This will search the found track on youtube.
|
||||
let stream = await play.stream(searched[0].url) // This will create stream from the above search
|
||||
|
||||
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);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const discord = require('discord.js')
|
||||
const { Intents } = require('discord.js')
|
||||
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
||||
const youtube = require('play-dl')
|
||||
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 >'
|
||||
@@ -17,13 +17,13 @@ client.on('messageCreate', async message => {
|
||||
})
|
||||
|
||||
let args = message.content.split('play ')[1].split(' ')[0]
|
||||
let stream = await youtube.stream(args, COOKIE)
|
||||
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 youtube.video_info(args, COOKIE)
|
||||
let yt_info = await play.video_info(args, COOKIE)
|
||||
console.log(yt_info.video_details.title)
|
||||
let stream = await youtube.stream_from_info(yt_info)
|
||||
let stream = await play.stream_from_info(yt_info)
|
||||
*/
|
||||
|
||||
let resource = createAudioResource(stream.stream, {
|
||||
@@ -1,7 +1,7 @@
|
||||
const discord = require('discord.js')
|
||||
const { Intents } = require('discord.js')
|
||||
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
||||
const youtube = require('play-dl')
|
||||
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 >'
|
||||
|
||||
@@ -16,8 +16,8 @@ client.on('messageCreate', async message => {
|
||||
})
|
||||
|
||||
let args = message.content.split('play')[1]
|
||||
let yt_info = await youtube.search(args, { limit : 1 })
|
||||
let stream = await youtube.stream(yt_info[0].url)
|
||||
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
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
const discord = require('discord.js')
|
||||
const { Intents } = require('discord.js')
|
||||
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
||||
const youtube = require('play-dl')
|
||||
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 >'
|
||||
|
||||
@@ -16,13 +16,13 @@ client.on('messageCreate', async message => {
|
||||
})
|
||||
|
||||
let args = message.content.split('play ')[1].split(' ')[0]
|
||||
let stream = await youtube.stream(args)
|
||||
let stream = await play.stream(args)
|
||||
/*
|
||||
OR if you want to get info about youtube link and then stream it
|
||||
|
||||
let yt_info = await youtube.video_info(args)
|
||||
let yt_info = await play.video_info(args)
|
||||
console.log(yt_info.video_details.title)
|
||||
let stream = await youtube.stream_from_info(yt_info)
|
||||
let stream = await play.stream_from_info(yt_info)
|
||||
*/
|
||||
|
||||
let resource = createAudioResource(stream.stream, {
|
||||
Reference in New Issue
Block a user