Cleaning the damn examples up
This commit is contained in:
parent
a4d182fdf3
commit
584dc1d7fa
@ -1,22 +1,27 @@
|
|||||||
const discord = require('discord.js')
|
const { Intents, Client } = require('discord.js')
|
||||||
const { Intents } = require('discord.js')
|
|
||||||
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
||||||
const play = 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 client = new 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 token = '< YOUR BOT TOKEN >'
|
||||||
|
|
||||||
|
|
||||||
client.on('messageCreate', async message => {
|
client.on('messageCreate', async message => {
|
||||||
if(message.content.startsWith('!play')){
|
if (message.content.startsWith('!play')) {
|
||||||
if(!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
|
|
||||||
|
if (!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
|
||||||
|
|
||||||
const connection = joinVoiceChannel({
|
const connection = joinVoiceChannel({
|
||||||
channelId : message.member.voice.channel.id,
|
channelId: message.member.voice.channel.id,
|
||||||
guildId : message.guild.id,
|
guildId: message.guild.id,
|
||||||
adapterCreator: message.guild.voiceAdapterCreator
|
adapterCreator: message.guild.voiceAdapterCreator
|
||||||
})
|
})
|
||||||
|
|
||||||
let args = message.content.split('play ')[1].split(' ')[0]
|
let args = message.content.split('play ')[1].split(' ')[0]
|
||||||
|
|
||||||
let stream = await play.stream(args)
|
let stream = await play.stream(args)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
OR if you want to get info about soundcloud link and then stream it
|
OR if you want to get info about soundcloud link and then stream it
|
||||||
|
|
||||||
@ -26,17 +31,19 @@ client.on('messageCreate', async message => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
let resource = createAudioResource(stream.stream, {
|
let resource = createAudioResource(stream.stream, {
|
||||||
inputType : stream.type
|
inputType: stream.type
|
||||||
})
|
})
|
||||||
|
|
||||||
let player = createAudioPlayer({
|
let player = createAudioPlayer({
|
||||||
behaviors: {
|
behaviors: {
|
||||||
noSubscriber: NoSubscriberBehavior.Play
|
noSubscriber: NoSubscriberBehavior.Play
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
player.play(resource)
|
player.play(resource)
|
||||||
|
|
||||||
connection.subscribe(player)
|
connection.subscribe(player)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
@ -44,4 +51,3 @@ client.on('ready', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
client.login(token);
|
client.login(token);
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +1,39 @@
|
|||||||
const discord = require('discord.js')
|
const { Intents, Client } = require('discord.js')
|
||||||
const { Intents } = require('discord.js')
|
|
||||||
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
||||||
const play = 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 client = new 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 token = '< Your Bot Token >'
|
||||||
|
|
||||||
|
|
||||||
client.on('messageCreate', async message => {
|
client.on('messageCreate', async message => {
|
||||||
if(message.content.startsWith('!play')){
|
if (message.content.startsWith('!play')) {
|
||||||
if(!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
|
|
||||||
|
if (!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
|
||||||
|
|
||||||
const connection = joinVoiceChannel({
|
const connection = joinVoiceChannel({
|
||||||
channelId : message.member.voice.channel.id,
|
channelId: message.member.voice.channel.id,
|
||||||
guildId : message.guild.id,
|
guildId: message.guild.id,
|
||||||
adapterCreator: message.guild.voiceAdapterCreator
|
adapterCreator: message.guild.voiceAdapterCreator
|
||||||
})
|
})
|
||||||
if(play.is_expired()){
|
|
||||||
|
if (play.is_expired()) {
|
||||||
await play.refreshToken() // This will check if access token has expired or not. If yes, then refresh the token.
|
await play.refreshToken() // This will check if access token has expired or not. If yes, then refresh the token.
|
||||||
}
|
}
|
||||||
let args = message.content.split('play ')[1].split(' ')[0]
|
|
||||||
|
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 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 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 stream = await play.stream(searched[0].url) // This will create stream from the above search
|
||||||
|
|
||||||
let resource = createAudioResource(stream.stream, {
|
let resource = createAudioResource(stream.stream, {
|
||||||
inputType : stream.type
|
inputType: stream.type
|
||||||
})
|
})
|
||||||
let player = createAudioPlayer({
|
let player = createAudioPlayer({
|
||||||
behaviors: {
|
behaviors: {
|
||||||
@ -33,12 +43,11 @@ client.on('messageCreate', async message => {
|
|||||||
player.play(resource)
|
player.play(resource)
|
||||||
|
|
||||||
connection.subscribe(player)
|
connection.subscribe(player)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
console.log(`We have logged in as ${client.user.tag}!`)
|
console.log(`We have logged in as ${client.user.tag}!`)
|
||||||
})
|
})
|
||||||
|
|
||||||
client.login(token);
|
client.login(token);
|
||||||
|
|
||||||
@ -1,35 +1,46 @@
|
|||||||
const discord = require('discord.js')
|
const { Intents, Client } = require('discord.js')
|
||||||
const { Intents } = require('discord.js')
|
|
||||||
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
||||||
const play = 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 client = new 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 token = '< YOUR BOT TOKEN >'
|
||||||
|
|
||||||
|
|
||||||
client.on('messageCreate', async message => {
|
client.on('messageCreate', async message => {
|
||||||
if(message.content.startsWith('!play')){
|
|
||||||
if(!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
|
if (message.content.startsWith('!play')) {
|
||||||
|
|
||||||
|
if (!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
|
||||||
|
|
||||||
const connection = joinVoiceChannel({
|
const connection = joinVoiceChannel({
|
||||||
channelId : message.member.voice.channel.id,
|
channelId: message.member.voice.channel.id,
|
||||||
guildId : message.guild.id,
|
guildId: message.guild.id,
|
||||||
adapterCreator: message.guild.voiceAdapterCreator
|
adapterCreator: message.guild.voiceAdapterCreator
|
||||||
})
|
})
|
||||||
|
|
||||||
let args = message.content.split('play')[1]
|
|
||||||
let yt_info = await play.search(args, { limit : 1 })
|
let args = message.content.split('play')[1]
|
||||||
let stream = await play.stream(yt_info[0].url)
|
let yt_info = await play.search(args, {
|
||||||
let resource = createAudioResource(stream.stream, {
|
limit: 1
|
||||||
inputType : stream.type
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let stream = await play.stream(yt_info[0].url)
|
||||||
|
|
||||||
|
let resource = createAudioResource(stream.stream, {
|
||||||
|
inputType: stream.type
|
||||||
|
})
|
||||||
|
|
||||||
let player = createAudioPlayer({
|
let player = createAudioPlayer({
|
||||||
behaviors: {
|
behaviors: {
|
||||||
noSubscriber: NoSubscriberBehavior.Play
|
noSubscriber: NoSubscriberBehavior.Play
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
player.play(resource)
|
player.play(resource)
|
||||||
|
|
||||||
connection.subscribe(player)
|
connection.subscribe(player)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
@ -37,4 +48,3 @@ client.on('ready', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
client.login(token);
|
client.login(token);
|
||||||
|
|
||||||
|
|||||||
@ -1,22 +1,28 @@
|
|||||||
const discord = require('discord.js')
|
const { Intents, Client } = require('discord.js')
|
||||||
const { Intents } = require('discord.js')
|
|
||||||
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
const { createAudioPlayer, createAudioResource , StreamType, demuxProbe, joinVoiceChannel, NoSubscriberBehavior, AudioPlayerStatus, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice')
|
||||||
const play = 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 client = new 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 token = '< YOUR BOT TOKEN >'
|
||||||
|
|
||||||
|
|
||||||
client.on('messageCreate', async message => {
|
client.on('messageCreate', async message => {
|
||||||
if(message.content.startsWith('!play')){
|
|
||||||
if(!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
|
if (message.content.startsWith('!play')) {
|
||||||
|
|
||||||
|
if (!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
|
||||||
|
|
||||||
const connection = joinVoiceChannel({
|
const connection = joinVoiceChannel({
|
||||||
channelId : message.member.voice.channel.id,
|
channelId: message.member.voice.channel.id,
|
||||||
guildId : message.guild.id,
|
guildId: message.guild.id,
|
||||||
adapterCreator: message.guild.voiceAdapterCreator
|
adapterCreator: message.guild.voiceAdapterCreator
|
||||||
})
|
})
|
||||||
|
|
||||||
let args = message.content.split('play ')[1].split(' ')[0]
|
let args = message.content.split('play ')[1].split(' ')[0]
|
||||||
|
|
||||||
let stream = await play.stream(args)
|
let stream = await play.stream(args)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
OR if you want to get info about youtube link and then stream it
|
OR if you want to get info about youtube link and then stream it
|
||||||
|
|
||||||
@ -26,17 +32,19 @@ client.on('messageCreate', async message => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
let resource = createAudioResource(stream.stream, {
|
let resource = createAudioResource(stream.stream, {
|
||||||
inputType : stream.type
|
inputType: stream.type
|
||||||
})
|
})
|
||||||
|
|
||||||
let player = createAudioPlayer({
|
let player = createAudioPlayer({
|
||||||
behaviors: {
|
behaviors: {
|
||||||
noSubscriber: NoSubscriberBehavior.Play
|
noSubscriber: NoSubscriberBehavior.Play
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
player.play(resource)
|
player.play(resource)
|
||||||
|
|
||||||
connection.subscribe(player)
|
connection.subscribe(player)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
@ -44,4 +52,3 @@ client.on('ready', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
client.login(token);
|
client.login(token);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user