Docs and examples updated

This commit is contained in:
killer069
2021-09-21 13:00:38 +05:30
parent c68a57aaf4
commit 3528f89607
14 changed files with 436 additions and 192 deletions

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 soundcloud link and then stream it
let so_info = await play.soundcloud(args) // Make sure that url is track url only. For playlist, make some logic.
console.log(so_info.name)
let stream = await play.stream_from_info(so_info)
*/
let resource = createAudioResource(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

@@ -1,3 +0,0 @@
const { Authorization } = require('play-dl');
Authorization()

View File

@@ -22,7 +22,7 @@ client.on('messageCreate', async message => {
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, {
let resource = createAudioResource(stream, {
inputType : stream.type
})
let player = createAudioPlayer({

View File

@@ -26,7 +26,7 @@ client.on('messageCreate', async message => {
let stream = await play.stream_from_info(yt_info, COOKIE)
*/
let resource = createAudioResource(stream.stream, {
let resource = createAudioResource(stream, {
inputType : stream.type
})
let player = createAudioPlayer({

View File

@@ -18,7 +18,7 @@ client.on('messageCreate', async message => {
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, {
let resource = createAudioResource(stream, {
inputType : stream.type
})
let player = createAudioPlayer({

View File

@@ -25,7 +25,7 @@ client.on('messageCreate', async message => {
let stream = await play.stream_from_info(yt_info)
*/
let resource = createAudioResource(stream.stream, {
let resource = createAudioResource(stream, {
inputType : stream.type
})
let player = createAudioPlayer({

3
examples/authorize.js Normal file
View File

@@ -0,0 +1,3 @@
const { authorization } = require('play-dl');
authorization()