Skip to content

Commit

Permalink
Adds Skip command
Browse files Browse the repository at this point in the history
Adds logger, to be able to log debug mode some function calls
  • Loading branch information
mbackermann committed Sep 15, 2021
1 parent efac7c1 commit 923f233
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 47 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

![DJ Arthas](/images/logo.jpg)

## Add Bot to your server
## Add DJ Arthas to your server
[Add me to your server](https://bit.ly/3nMRhnB)

## Installation
1. Install dependencies
```
yarn install
# or
# or
npm install
```

Expand Down Expand Up @@ -48,12 +48,14 @@ npm start
### `/help`
- List bot's commands
### `/pause`
- Pauses the current song.
- Pauses the current track.
### `/ping`
- Just a ping. I will reply with a pong.
### `/play [terms or url]`
- Play a song based on your search terms or url
- Play a track based on your search terms or url
### `/resume`
- Resumes the current song
- Resumes the current track
### `/skip`
- Skip the current track
### `/stop`
- Stops the current queue and clears it
2 changes: 1 addition & 1 deletion commands/bot-commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
emoji: '❓',
execute(interaction, player) {
let msg = '**I can answer the following commands**'
const commands = player.client.commands
player.client.commands
.sort((a, b) => {
if (a.key < b.key) {
return -1
Expand Down
11 changes: 6 additions & 5 deletions commands/bot-commands/pause.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { GuildMember } = require('discord.js')
const Logger = require('../../logger/Logger')

module.exports = {
name: 'pause',
description: 'Pause your current song',
description: 'Pause your current track',
emoji: '⏸',
async execute(interaction, player) {
try {
Expand Down Expand Up @@ -31,17 +32,17 @@ module.exports = {
const queue = player.getQueue(interaction.guildId)
if (!queue || !queue.playing) {
return void interaction.followUp({
content: "❌ There's no song being played",
content: "❌ There's no track being played",
})
}
const paused = queue.setPaused(true)
return void interaction.followUp({
content: paused ? '⏸ | Paused!' : "❌ | Couldn't pause your song",
content: paused ? '⏸ | Paused!' : "❌ | Couldn't pause your track",
})
} catch (error) {
console.log(error)
Logger.log(error)
interaction.followUp({
content: `There was an error trying to pause your song: ${error.message}`,
content: `There was an error trying to pause your track: ${error.message}`,
})
}
},
Expand Down
7 changes: 4 additions & 3 deletions commands/bot-commands/play.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { GuildMember } = require('discord.js')
const { QueryType } = require('discord-player')
const Logger = require('../../logger/Logger')

module.exports = {
name: 'play',
description: 'Play a song based on your search terms or url',
description: 'Play a track based on your search terms or url',
emoji: '🎶',
options: [
{
Expand Down Expand Up @@ -84,10 +85,10 @@ module.exports = {
: queue.addTrack(searchResult.tracks[0])
if (!queue.playing) await queue.play()
} catch (error) {
console.log(error)
Logger.log(error)
interaction.followUp({
content:
'There was an error trying to add your song to queue: ' +
'There was an error trying to add your track to queue: ' +
error.message,
})
}
Expand Down
11 changes: 6 additions & 5 deletions commands/bot-commands/resume.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { GuildMember } = require('discord.js')
const Logger = require('../../logger/Logger')

module.exports = {
name: 'resume',
description: 'Resume current song',
description: 'Resume current track',
emoji: '▶',
async execute(interaction, player) {
try {
Expand Down Expand Up @@ -31,17 +32,17 @@ module.exports = {
const queue = player.getQueue(interaction.guildId)
if (!queue || !queue.playing) {
return void interaction.followUp({
content: "❌ There's no song being played",
content: "❌ There's no track being played",
})
}
const resumed = queue.setPaused(false)
return void interaction.followUp({
content: resumed ? '▶ | Resumed!' : "❌ | Couldn't resume your song",
content: resumed ? '▶ | Resumed!' : "❌ | Couldn't resume your track",
})
} catch (error) {
console.log(error)
Logger.log(error)
interaction.followUp({
content: `There was an error trying to resume your song: ${error.message}`,
content: `There was an error trying to resume your track: ${error.message}`,
})
}
},
Expand Down
51 changes: 51 additions & 0 deletions commands/bot-commands/skip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { GuildMember } = require('discord.js')
const Logger = require('../../logger/Logger')

module.exports = {
name: 'skip',
description: 'Skip the current track',
emoji: '⏭️',
async execute(interaction, player) {
try {
if (
!(interaction.member instanceof GuildMember) ||
!interaction.member.voice.channel
) {
return void interaction.reply({
content: 'You are not in a voice channel!',
ephemeral: true,
})
}

if (
interaction.guild.me.voice.channelId &&
interaction.member.voice.channelId !==
interaction.guild.me.voice.channelId
) {
return void interaction.reply({
content: 'You are not in my voice channel!',
ephemeral: true,
})
}

await interaction.deferReply()
const queue = player.getQueue(interaction.guildId)
if (!queue || !queue.playing) {
return void interaction.followUp({
content: "❌ There's no track being played",
})
}
const skipped = queue.skip()
return void interaction.followUp({
content: skipped
? `⏭️ | Skipped current track`
: `❌ | Coulnd't skip this track!`,
})
} catch (error) {
Logger.log(error)
interaction.followUp({
content: `There was an error trying to skip your track: ${error.message}`,
})
}
},
}
7 changes: 4 additions & 3 deletions commands/bot-commands/stop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { GuildMember } = require('discord.js')
const Logger = require('../../logger/Logger')

module.exports = {
name: 'stop',
Expand Down Expand Up @@ -31,17 +32,17 @@ module.exports = {
const queue = player.getQueue(interaction.guildId)
if (!queue || !queue.playing) {
return void interaction.followUp({
content: "❌ There's no song being played",
content: "❌ There's no track being played",
})
}
queue.destroy()
return void interaction.followUp({
content: '🛑 | Stopped the player!',
})
} catch (error) {
console.log(error)
Logger.log(error)
interaction.followUp({
content: `There was an error trying to stop your song: ${error.message}`,
content: `There was an error trying to stop your track: ${error.message}`,
})
}
},
Expand Down
7 changes: 4 additions & 3 deletions commands/registerSlashCommands.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { REST } = require('@discordjs/rest')
const { Routes } = require('discord-api-types/v9')
const Logger = require('../logger/Logger')

const registerSlashCommands = async (guildIds, client) => {
const rest = new REST({ version: '9' }).setToken(client.config.token)
try {
console.log('Started refreshing application (/) commands.')
Logger.log('Started refreshing application (/) commands.')
guildIds.forEach(async (guildId) => {
await rest.put(
Routes.applicationGuildCommands(client.config.clientId, guildId),
Expand All @@ -13,9 +14,9 @@ const registerSlashCommands = async (guildIds, client) => {
}
)
})
console.log('Successfully reloaded application (/) commands.')
Logger.log('Successfully reloaded application (/) commands.')
} catch (error) {
console.error(error)
Logger.error(error)
}
}

Expand Down
1 change: 0 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module.exports = {
try {
initialVolume = parseInt(process.env.BOT_INITIAL_VOLUME)
} catch (error) {
console.error(error)
initialVolume = 100
}
return initialVolume
Expand Down
9 changes: 5 additions & 4 deletions guildsTimeout/GuildsTimeout.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Logger = require('../logger/Logger')
class GuildsTimeout {
constructor(client) {
this.config = client.config
Expand All @@ -9,19 +10,19 @@ class GuildsTimeout {
if (!this.config.leaveOnEnd || this.config.leaveOnEndTimeout == 0) return

let timeout = setTimeout(() => {
console.log('Timeout!')
Logger.log('Timeout!')
try {
queue.connection.disconnect()
} catch (error) {
console.error(
Logger.error(
'Error trying to disconnect after leaveOnEndCooldown',
error
)
}
}, this.config.leaveOnEndTimeout * 1000)
this.timeouts.set(queue.guild.id, timeout)
} catch (error) {
console.error(error)
Logger.error(error)
}
}

Expand All @@ -34,7 +35,7 @@ class GuildsTimeout {
this.timeouts.delete(queue.guild.id)
}
} catch (error) {
console.error(error)
Logger.error(error)
}
}
}
Expand Down
Loading

0 comments on commit 923f233

Please sign in to comment.