diff --git a/src/events/interactions/interactionCreate.js b/src/events/interactions/interactionCreate.js index bae917c..398901d 100644 --- a/src/events/interactions/interactionCreate.js +++ b/src/events/interactions/interactionCreate.js @@ -1,5 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions, botOptions } = require('../../config'); +const { cannotSendMessageInChannel } = require('../../utils/validation/permissionValidator'); const { Events, EmbedBuilder } = require('discord.js'); module.exports = { @@ -10,6 +11,10 @@ module.exports = { return; } + if (await cannotSendMessageInChannel(interaction)) { + return; + } + const command = client.commands.get(interaction.commandName); if (!command) { logger.warn( diff --git a/src/utils/validation/permissionValidator.js b/src/utils/validation/permissionValidator.js index 5a308f4..f88aa34 100644 --- a/src/utils/validation/permissionValidator.js +++ b/src/utils/validation/permissionValidator.js @@ -10,13 +10,42 @@ exports.cannotJoinVoiceOrTalk = async (interaction) => { embeds: [ new EmbedBuilder() .setDescription( - `**${embedOptions.icons.warning} Oops!**\nI do not have permission to play audio in the voice channel you are in.\n\nPlease make sure I have the **Connect** and **Speak** permissions in this voice channel.` + `**${embedOptions.icons.warning} Oops!**\nI do not have permission to play audio in the voice channel you are in.\n\nPlease make sure I have the **\`Connect\`** and **\`Speak\`** permissions in this voice channel.` ) .setColor(embedOptions.colors.warning) ] }); - logger.debug(`User tried to use command ${interaction.commandName} but was not in a voice channel.`); + logger.debug( + `User tried to use command ${interaction.commandName} but the bot had no permission to join/speak in the voice channel.` + ); + return true; + } + + return false; +}; + +exports.cannotSendMessageInChannel = async (interaction) => { + const channel = interaction.channel; + + // only checks if channel is viewable, as bot will have permission to send interaction replies if channel is viewable + if (!channel.viewable) { + // we can still send ephemeral replies in channels we can't view, so sending message to user instead + await interaction.deferReply({ ephemeral: true }); + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedOptions.icons.warning} Oops!**\nI do not have permission to send message replies in the channel you are in.\n\nPlease make sure I have the **\`View Channel\`** permission in this text channel.` + ) + .setColor(embedOptions.colors.warning) + ], + ephemeral: true + }); + + logger.debug( + `User tried to use command ${interaction.commandName} but the bot had no permission to send reply in text channel.` + ); return true; }