Move deferring into the specific interactions where required. Makes especially validation warnings ephemeral.

This commit is contained in:
Marius Begby committed 2024-01-30 19:21:42 +01:00
1 parent a7aefd085f
commit f3329fceee
36 files changed
+164 -175

No files matched your search

+25 -29
View File
@@ -32,7 +32,7 @@ export const checkVoicePermissionJoinAndTalk = async ({ interaction, executionId
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
if (channel instanceof VoiceChannel && (!channel.joinable || !channel.speakable)) {
await interaction.editReply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
@@ -49,7 +49,8 @@ export const checkVoicePermissionJoinAndTalk = async ({ interaction, executionId
: interaction.user.username,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
})
]
],
ephemeral: true
});
logger.debug(
@@ -83,34 +84,29 @@ export const checkChannelPermissionViewable = async ({ interaction, executionId
);
try {
// we can still send ephemeral replies in channels we can't view, so sending message to user instead
if (!interaction.deferred && !interaction.replied) {
logger.debug('Interaction was not deferred or replied to yet. Deferring reply as ephemeral.');
await interaction.deferReply({ ephemeral: true });
logger.debug(
'Sending ephemeral message in channel about insufficient permissions to send message in channel.'
);
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
translator('validation.cannotSendMessageInChannel', {
icon: embedOptions.icons.warning,
channel: `<#${channel.id}>`
})
)
.setColor(embedOptions.colors.warning)
.setFooter({
text:
interaction.member instanceof GuildMember
? interaction.member.nickname || interaction.user.username
: interaction.user.username,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
logger.debug(
'Sending ephemeral message in channel about insufficient permissions to send message in channel.'
);
await interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
translator('validation.cannotSendMessageInChannel', {
icon: embedOptions.icons.warning,
channel: `<#${channel.id}>`
})
]
});
}
)
.setColor(embedOptions.colors.warning)
.setFooter({
text:
interaction.member instanceof GuildMember
? interaction.member.nickname || interaction.user.username
: interaction.user.username,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
})
],
ephemeral: true
});
} catch (error) {
if (error instanceof Error) {
if (error.message == 'The reply to this interaction has already been sent or deferred.') {
+12 -8
View File
@@ -23,7 +23,7 @@ export const checkQueueExists = async ({ interaction, queue, executionId }: Vali
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
if (!queue) {
await interaction.editReply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
@@ -40,7 +40,8 @@ export const checkQueueExists = async ({ interaction, queue, executionId }: Vali
: interaction.user.username,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
})
]
],
ephemeral: true
});
logger.debug(`User tried to use command '${interactionIdentifier}' but there was no queue.`);
@@ -64,7 +65,7 @@ export const checkHistoryExists = async ({ interaction, history, executionId }:
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
if (!history) {
await interaction.editReply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
@@ -81,7 +82,8 @@ export const checkHistoryExists = async ({ interaction, history, executionId }:
: interaction.user.username,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
})
]
],
ephemeral: true
});
logger.debug(`User tried to use command '${interactionIdentifier}' but there was no history.`);
@@ -105,7 +107,7 @@ export const checkQueueCurrentTrack = async ({ interaction, queue, executionId }
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
if (queue && !queue.currentTrack) {
await interaction.editReply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
@@ -122,7 +124,8 @@ export const checkQueueCurrentTrack = async ({ interaction, queue, executionId }
: interaction.user.username,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
})
]
],
ephemeral: true
});
logger.debug(`User tried to use command '${interactionIdentifier}' but there was no current track.`);
@@ -146,7 +149,7 @@ export const checkQueueEmpty = async ({ interaction, queue, executionId }: Valid
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
if (queue && queue.tracks.data.length === 0) {
await interaction.editReply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
@@ -163,7 +166,8 @@ export const checkQueueEmpty = async ({ interaction, queue, executionId }: Valid
: interaction.user.username,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
})
]
],
ephemeral: true
});
logger.debug(`User tried to use command '${interactionIdentifier}' but there was no tracks in the queue.`);
@@ -24,7 +24,7 @@ export const checkValidGuildId = async ({ interaction, executionId }: ValidatorP
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
if (interaction.guildId && !systemOptions.systemGuildIds.includes(interaction.guildId)) {
await interaction.editReply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
@@ -34,7 +34,8 @@ export const checkValidGuildId = async ({ interaction, executionId }: ValidatorP
})
)
.setColor(embedOptions.colors.warning)
]
],
ephemeral: true
});
logger.debug(
@@ -22,7 +22,7 @@ export const checkInVoiceChannel = async ({ interaction, executionId }: Validato
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
if (interaction.member instanceof GuildMember && !interaction.member.voice.channel) {
await interaction.editReply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
@@ -35,7 +35,8 @@ export const checkInVoiceChannel = async ({ interaction, executionId }: Validato
text: interaction.member.nickname || interaction.user.username,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
})
]
],
ephemeral: true
});
logger.debug(`User tried to use command '${interactionIdentifier}' but was not in a voice channel.`);
@@ -67,7 +68,7 @@ export const checkSameVoiceChannel = async ({ interaction, queue, executionId }:
interaction.member instanceof GuildMember &&
interaction.member.voice.channel?.id !== queue.dispatcher.channel.id
) {
await interaction.editReply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
@@ -81,7 +82,8 @@ export const checkSameVoiceChannel = async ({ interaction, queue, executionId }:
text: interaction.member.nickname || interaction.user.username,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
})
]
],
ephemeral: true
});
logger.debug(`User tried to use command '${interactionIdentifier}' but was not in the same voice channel.`);