mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 00:10:58 -05:00
Some fine-tuning i might add.
This commit is contained in:
parent
5abed4445f
commit
b4cc606be4
@ -4,7 +4,7 @@ import {Player,useTimeline,useQueue} from 'discord-player';
|
|||||||
import {SpotifyExtractor} from '@discord-player/extractor';
|
import {SpotifyExtractor} from '@discord-player/extractor';
|
||||||
export default {
|
export default {
|
||||||
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
|
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
|
||||||
if (!client.config.botSwitches.music) return interaction.reply({content:'Music module is currently disabled.',ephemeral:true});
|
if (!client.config.botSwitches.music && !client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content:'Music module is currently disabled.',ephemeral:true});
|
||||||
if (!client.isStaff(interaction.member) && !client.config.whitelist.includes(interaction.member.id)) return interaction.reply('This command is in early stages of development, some parts may be missing or broken.\nIt has been restricted to staff for time-being.');
|
if (!client.isStaff(interaction.member) && !client.config.whitelist.includes(interaction.member.id)) return interaction.reply('This command is in early stages of development, some parts may be missing or broken.\nIt has been restricted to staff for time-being.');
|
||||||
const player = Player.singleton(client);
|
const player = Player.singleton(client);
|
||||||
await player.extractors.register(SpotifyExtractor, {
|
await player.extractors.register(SpotifyExtractor, {
|
||||||
@ -33,12 +33,18 @@ export default {
|
|||||||
const url = interaction.options.getString('url');
|
const url = interaction.options.getString('url');
|
||||||
if (!url.includes('https://open.spotify.com/')) return interaction.reply('Sorry, I can\'t play that. I can only accept Spotify links that contains `https://open.spotify.com/`');
|
if (!url.includes('https://open.spotify.com/')) return interaction.reply('Sorry, I can\'t play that. I can only accept Spotify links that contains `https://open.spotify.com/`');
|
||||||
player.play(interaction.member.voice.channel, url);
|
player.play(interaction.member.voice.channel, url);
|
||||||
await interaction.reply(`Added the song to the queue.`);
|
await interaction.reply(`Added the ${url.includes('playlist/') ? 'playlist' : 'song'} to the queue.`);
|
||||||
},
|
},
|
||||||
stop: async()=>{
|
stop: async()=>{
|
||||||
player.destroy();
|
player.destroy();
|
||||||
await interaction.reply('Player destroyed.')
|
await interaction.reply('Player destroyed.')
|
||||||
},
|
},
|
||||||
|
pause: ()=>{
|
||||||
|
const queue = useQueue(interaction.guildId);
|
||||||
|
queue.node.setPaused(!queue.node.isPaused());
|
||||||
|
if (!queue.node.isPaused) interaction.reply('Music has been paused.');
|
||||||
|
else if (queue.node.isPaused) interaction.reply('Music has been unpaused.')
|
||||||
|
},
|
||||||
now_playing: ()=>{
|
now_playing: ()=>{
|
||||||
const {volume,timestamp,track} = useTimeline(interaction.guildId);
|
const {volume,timestamp,track} = useTimeline(interaction.guildId);
|
||||||
interaction.reply({embeds:[
|
interaction.reply({embeds:[
|
||||||
@ -48,11 +54,22 @@ export default {
|
|||||||
)
|
)
|
||||||
]})
|
]})
|
||||||
},
|
},
|
||||||
|
queue: async()=>{
|
||||||
|
const queue = useQueue(interaction.guildId);
|
||||||
|
await interaction.reply({embeds:[new client.embed().setColor(client.config.embedColor).setTitle(`Songs currently in the queue: ${queue.tracks.size}`).setDescription(queue.tracks.size > 0 ? `${queue.tracks.map(i=>`**${i.title}** - **${i.author}**`).join('\n')}` : '*No songs currently queued.*')]}).catch(()=>interaction.channel.send('I cannot send an embed that hits beyond the character limit.'))
|
||||||
|
},
|
||||||
volume: ()=>{
|
volume: ()=>{
|
||||||
const vol = interaction.options.getNumber('percentage');
|
const vol = interaction.options.getNumber('percentage');
|
||||||
const queue = useQueue(interaction.guildId);
|
useQueue(interaction.guildId).node.setVolume(vol);
|
||||||
queue.node.setVolume(vol);
|
|
||||||
interaction.reply(`Successfully adjusted the player's volume to ${vol}%`)
|
interaction.reply(`Successfully adjusted the player's volume to ${vol}%`)
|
||||||
|
},
|
||||||
|
shuffle: ()=>{
|
||||||
|
useQueue(interaction.guildId).tracks.shuffle();
|
||||||
|
interaction.reply('Songs in the queue has been shuffled.')
|
||||||
|
},
|
||||||
|
remove: ()=>{
|
||||||
|
useQueue(interaction.guildId).removeTrack(interaction.options.getNumber('id',true));
|
||||||
|
interaction.reply('Song has been removed from the queue.')
|
||||||
}
|
}
|
||||||
} as any)[interaction.options.getSubcommand()]();
|
} as any)[interaction.options.getSubcommand()]();
|
||||||
},
|
},
|
||||||
@ -69,16 +86,34 @@ export default {
|
|||||||
.addSubcommand(x=>x
|
.addSubcommand(x=>x
|
||||||
.setName('stop')
|
.setName('stop')
|
||||||
.setDescription('Stop playing music and disconnect the bot from voice channel'))
|
.setDescription('Stop playing music and disconnect the bot from voice channel'))
|
||||||
|
.addSubcommand(x=>x
|
||||||
|
.setName('pause')
|
||||||
|
.setDescription('Pause/unpause the music'))
|
||||||
.addSubcommand(x=>x
|
.addSubcommand(x=>x
|
||||||
.setName('now_playing')
|
.setName('now_playing')
|
||||||
.setDescription('Check what song is currently playing'))
|
.setDescription('Check what song is currently playing'))
|
||||||
|
.addSubcommand(x=>x
|
||||||
|
.setName('queue')
|
||||||
|
.setDescription('View the list of songs currently in queue'))
|
||||||
.addSubcommand(x=>x
|
.addSubcommand(x=>x
|
||||||
.setName('volume')
|
.setName('volume')
|
||||||
.setDescription('Adjust the player\'s volume')
|
.setDescription('Adjust the player\'s volume')
|
||||||
.addNumberOption(x=>x
|
.addNumberOption(x=>x
|
||||||
.setName('percentage')
|
.setName('percentage')
|
||||||
.setDescription('Volume level to adjust, ranges from 5 to 100, default is 75')
|
.setDescription('Adjust the volume level, ranges from 5 to 100, default is 75')
|
||||||
.setMaxValue(100)
|
.setMaxValue(100)
|
||||||
.setMinValue(5)
|
.setMinValue(5)
|
||||||
.setRequired(true)))
|
.setRequired(true)))
|
||||||
|
.addSubcommand(x=>x
|
||||||
|
.setName('shuffle')
|
||||||
|
.setDescription('Shuffle the songs in a queue'))
|
||||||
|
.addSubcommand(x=>x
|
||||||
|
.setName('remove')
|
||||||
|
.setDescription('Remove a specific song from the queue')
|
||||||
|
.addNumberOption(x=>x
|
||||||
|
.setName('id')
|
||||||
|
.setDescription('Song # in the queue to be removed')
|
||||||
|
.setMinValue(0)
|
||||||
|
.setMaxValue(9999)
|
||||||
|
.setRequired(true)))
|
||||||
}
|
}
|
20
src/index.ts
20
src/index.ts
@ -42,16 +42,24 @@ client.on('error', (error: Error)=>DZ(error, 'client-error'));
|
|||||||
|
|
||||||
// Audio Player event handling
|
// Audio Player event handling
|
||||||
if (client.config.botSwitches.music){
|
if (client.config.botSwitches.music){
|
||||||
player.events.on('playerStart', (queue,track)=>queue.channel.send({embeds:[new client.embed().setColor(client.config.embedColor).setTitle(`${track.raw.title} - ${track.raw.author}`).setFooter({text:`Playing in ${queue.channel.name}`}).setThumbnail(track.raw.thumbnail)]}));
|
const playerEmbed =(color:Discord.ColorResolvable,title:string,thumbnail?:string,footer?:string)=>{
|
||||||
player.events.on('playerFinish', (queue,track)=>{
|
const embed = new client.embed().setColor(color).setTitle(title);
|
||||||
|
if (thumbnail) embed.setThumbnail(thumbnail);
|
||||||
|
if (footer) embed.setFooter({text:footer})
|
||||||
|
return embed
|
||||||
|
}
|
||||||
|
player.events.on('playerStart', (queue,track)=>queue.channel.send({embeds:[playerEmbed(client.config.embedColor, `Next up: ${track.raw.title} - ${track.raw.author}`,track.raw.thumbnail)]}));
|
||||||
|
player.events.on('audioTrackAdd', (queue,track)=>queue.channel.send({embeds:[playerEmbed(client.config.embedColorGreen, `Added: ${track.raw.title} - ${track.raw.author}`,track.raw.thumbnail)]}));
|
||||||
|
player.events.on('audioTrackRemove', (queue, track)=>queue.channel.send({embeds:[playerEmbed(client.config.embedColor, `Removed: ${track.raw.title} - ${track.raw.author}`,track.raw.thumbnail)]}));
|
||||||
|
player.events.on('emptyQueue', queue=>{
|
||||||
if (queue.tracks.size < 1) return queue.channel.send('There\'s no songs left in the queue, leaving voice channel in 15 seconds.').then(()=>setTimeout(()=>queue.connection.disconnect(), 15000))
|
if (queue.tracks.size < 1) return queue.channel.send('There\'s no songs left in the queue, leaving voice channel in 15 seconds.').then(()=>setTimeout(()=>queue.connection.disconnect(), 15000))
|
||||||
})
|
});
|
||||||
player.events.on('audioTrackAdd', (queue,track)=>queue.channel.send({embeds:[new client.embed().setColor(client.config.embedColorGreen).setTitle(`${track.raw.title} - ${track.raw.author}`).setFooter({text:`Added to queue`}).setThumbnail(track.raw.thumbnail)]}));
|
player.events.on('playerPause', queue=>queue.channel.send({embeds:[playerEmbed(client.config.embedColor, 'Player has been paused.\nRun the command to unpause it')]}));
|
||||||
/* player.events.on('debug', (queue,message)=>{
|
/* player.events.on('debug', (queue,message)=>{
|
||||||
console.log(client.logTime(), message)
|
console.log(client.logTime(), message)
|
||||||
}) */
|
}) */
|
||||||
player.events.on('playerError', (queue, error)=>DZ(error, 'playerError'));
|
player.events.on('playerError', (queue, error)=>DZ(error, 'playerError')); // I don't know if both of these actually works, because most
|
||||||
player.events.on('error', (queue, error)=>DZ(error, 'playerInternalError'));
|
player.events.on('error', (queue, error)=>DZ(error, 'playerInternalError')); // errors from the player is coming from unhandledRejection
|
||||||
}
|
}
|
||||||
|
|
||||||
// YouTube Upload notification and Daggerwin MP loop
|
// YouTube Upload notification and Daggerwin MP loop
|
||||||
|
Loading…
Reference in New Issue
Block a user