Skip to content

Commit

Permalink
fixes permission error when trying to join a voice channel that the b…
Browse files Browse the repository at this point in the history
…ot doesnt have permission
  • Loading branch information
mbackermann committed Sep 16, 2021
1 parent 1076e13 commit a17f32f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/Client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Client, Intents, Collection } = require('discord.js')
const fs = require('fs')
const Logger = require('../logger/Logger')

class DiscordClient extends Client {
constructor(config) {
Expand Down
11 changes: 11 additions & 0 deletions commands/bot-commands/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ module.exports = {
})
}

const permissions = interaction.member.voice.channel.permissionsFor(
interaction.guild.me
)

if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
return void interaction.reply({
content: "I don't have permission to join your voice channel!",
ephemeral: true,
})
}

await interaction.deferReply()
const queue = player.getQueue(interaction.guildId)
if (!queue || !queue.playing) {
Expand Down
11 changes: 11 additions & 0 deletions commands/bot-commands/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ module.exports = {
})
}

const permissions = interaction.member.voice.channel.permissionsFor(
interaction.guild.me
)

if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
return void interaction.reply({
content: "I don't have permission to join your voice channel!",
ephemeral: true,
})
}

await interaction.deferReply()

const search = interaction.options.get('search').value
Expand Down
11 changes: 11 additions & 0 deletions commands/bot-commands/resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ module.exports = {
})
}

const permissions = interaction.member.voice.channel.permissionsFor(
interaction.guild.me
)

if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
return void interaction.reply({
content: "I don't have permission to join your voice channel!",
ephemeral: true,
})
}

await interaction.deferReply()
const queue = player.getQueue(interaction.guildId)
if (!queue || !queue.playing) {
Expand Down
11 changes: 11 additions & 0 deletions commands/bot-commands/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ module.exports = {
})
}

const permissions = interaction.member.voice.channel.permissionsFor(
interaction.guild.me
)

if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
return void interaction.reply({
content: "I don't have permission to join your voice channel!",
ephemeral: true,
})
}

await interaction.deferReply()
const queue = player.getQueue(interaction.guildId)
if (!queue || !queue.playing) {
Expand Down
11 changes: 11 additions & 0 deletions commands/bot-commands/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ module.exports = {
})
}

const permissions = interaction.member.voice.channel.permissionsFor(
interaction.guild.me
)

if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
return void interaction.reply({
content: "I don't have permission to join your voice channel!",
ephemeral: true,
})
}

await interaction.deferReply()
const queue = player.getQueue(interaction.guildId)
if (!queue || !queue.playing) {
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const guildsTimeout = new GuildsTimeout(client)
client.once('ready', async (client) => {
Logger.log('Discord Bot ready!')
Logger.debug('Client ready', client)
await client.user.setActivity('/help', { type: 'LISTENING' })
client.clearAdminMessages()
client.user.setActivity('/help', { type: 'LISTENING' })
const guildIds = Array.from((await client.guilds.fetch()).keys())
registerSlashCommands(guildIds, client)
})
Expand Down

0 comments on commit a17f32f

Please sign in to comment.