Cleaning the damn examples up

This commit is contained in:
DarkInk 2022-01-24 18:31:00 -06:00
parent a4d182fdf3
commit 584dc1d7fa
4 changed files with 89 additions and 57 deletions

View File

@ -1,22 +1,27 @@
const discord = require('discord.js')
const { Intents } = require('discord.js')
const { Intents, Client } = 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 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 >'
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({
channelId : message.member.voice.channel.id,
guildId : message.guild.id,
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
@ -26,13 +31,15 @@ client.on('messageCreate', async message => {
*/
let resource = createAudioResource(stream.stream, {
inputType : stream.type
inputType: stream.type
})
let player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play
}
})
player.play(resource)
connection.subscribe(player)
@ -44,4 +51,3 @@ client.on('ready', () => {
})
client.login(token);

View File

@ -1,29 +1,39 @@
const discord = require('discord.js')
const { Intents } = require('discord.js')
const { Intents, Client } = 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 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 >'
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({
channelId : message.member.voice.channel.id,
guildId : message.guild.id,
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
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.
}
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 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
inputType: stream.type
})
let player = createAudioPlayer({
behaviors: {
@ -41,4 +51,3 @@ client.on('ready', () => {
})
client.login(token);

View File

@ -1,31 +1,42 @@
const discord = require('discord.js')
const { Intents } = require('discord.js')
const { Intents, Client } = 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 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 >'
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({
channelId : message.member.voice.channel.id,
guildId : message.guild.id,
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 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)
@ -37,4 +48,3 @@ client.on('ready', () => {
})
client.login(token);

View File

@ -1,22 +1,28 @@
const discord = require('discord.js')
const { Intents } = require('discord.js')
const { Intents, Client } = 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 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 >'
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({
channelId : message.member.voice.channel.id,
guildId : message.guild.id,
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
@ -26,13 +32,15 @@ client.on('messageCreate', async message => {
*/
let resource = createAudioResource(stream.stream, {
inputType : stream.type
inputType: stream.type
})
let player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play
}
})
player.play(resource)
connection.subscribe(player)
@ -44,4 +52,3 @@ client.on('ready', () => {
})
client.login(token);