added examples
This commit is contained in:
parent
b776a4868f
commit
a05ea18589
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
node_modules/
|
||||
dist/
|
||||
.npmrc
|
||||
.npmrc
|
||||
examples/node_modules
|
||||
examples/package-lock.json
|
||||
25
examples/package.json
Normal file
25
examples/package.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "play-dl",
|
||||
"version": "0.3.0",
|
||||
"description": "YouTube, SoundCloud, Spotify downloader",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/play-dl/play-dl"
|
||||
},
|
||||
"author": "Killer069",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/play-dl/play-dl/issues"
|
||||
},
|
||||
"homepage": "https://github.com/play-dl/play-dl#readme",
|
||||
"files": [
|
||||
"dist/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"@discordjs/opus": "^0.5.3",
|
||||
"@discordjs/voice": "^0.5.6",
|
||||
"discord.js": "^13.1.0",
|
||||
"libsodium-wrappers": "^0.7.9",
|
||||
"play-dl": "^0.3.0"
|
||||
}
|
||||
}
|
||||
40
examples/play(search).js
Normal file
40
examples/play(search).js
Normal 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 youtube = 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 youtube.search(args, { limit : 1 })
|
||||
let stream = await youtube.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);
|
||||
|
||||
47
examples/play(url).js
Normal file
47
examples/play(url).js
Normal 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 youtube = 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 youtube.stream(args)
|
||||
/*
|
||||
OR if you want to get info about youtube link and then stream it
|
||||
|
||||
let yt_info = await youtube.video_info(args)
|
||||
console.log(yt_info.video_details.title)
|
||||
let stream = await youtube.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);
|
||||
|
||||
56
examples/play[LiveStream(search)].js
Normal file
56
examples/play[LiveStream(search)].js
Normal file
@ -0,0 +1,56 @@
|
||||
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 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 youtube.search(args)
|
||||
let stream = await youtube.stream(yt_info[0].url)
|
||||
/*
|
||||
OR if you want to stream Live Video have less delay
|
||||
|
||||
let stream = await youtube.stream(yt_info[0].url, { actual_live : true })
|
||||
|
||||
OR if you want higher quality audio Live Stream
|
||||
|
||||
let stream = await youtube.stream(yt_info[0].url, { preferred_quality : "480p"}) // You can have resolution upto 1080p
|
||||
|
||||
Default : preferred_quality : "144p"
|
||||
|
||||
OR both
|
||||
|
||||
let stream = await youtube.stream(yt_info[0].url, { actual_live : true ,preferred_quality : "480p"})
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
55
examples/play[LiveStream(url)].js
Normal file
55
examples/play[LiveStream(url)].js
Normal file
@ -0,0 +1,55 @@
|
||||
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 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 youtube.stream(args)
|
||||
/*
|
||||
OR if you want to stream Live Video have less delay
|
||||
|
||||
let stream = await youtube.stream(args, { actual_live : true })
|
||||
|
||||
OR if you want higher quality audio Live Stream
|
||||
|
||||
let stream = await youtube.stream(args, { preferred_quality : "480p"}) // You can have resolution upto 1080p
|
||||
|
||||
Default : preferred_quality : "144p"
|
||||
|
||||
OR both
|
||||
|
||||
let stream = await youtube.stream(args, { actual_live : true ,preferred_quality : "480p"})
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user