mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 06:28:53 +00:00
fix: Added check on text channel permissions on intereactionCreate
This commit is contained in:
1 parent
b68b7dac95
commit
0c7a627e83
2 files changed
+36
-2
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
const logger = require('../../services/logger');
|
const logger = require('../../services/logger');
|
||||||
const { embedOptions, botOptions } = require('../../config');
|
const { embedOptions, botOptions } = require('../../config');
|
||||||
|
const { cannotSendMessageInChannel } = require('../../utils/validation/permissionValidator');
|
||||||
const { Events, EmbedBuilder } = require('discord.js');
|
const { Events, EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -10,6 +11,10 @@ module.exports = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (await cannotSendMessageInChannel(interaction)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const command = client.commands.get(interaction.commandName);
|
const command = client.commands.get(interaction.commandName);
|
||||||
if (!command) {
|
if (!command) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
|
|||||||
@@ -10,13 +10,42 @@ exports.cannotJoinVoiceOrTalk = async (interaction) => {
|
|||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.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)
|
.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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user