mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 01:05:30 +01:00
Handle if queue reply is deleted
This commit is contained in:
parent
09908f4af5
commit
812d01edbd
13
src/bot.ts
13
src/bot.ts
|
@ -70,11 +70,14 @@ export default class {
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
debug(error);
|
debug(error);
|
||||||
|
|
||||||
if (interaction.replied || interaction.deferred) {
|
// This can fail if the message was deleted, and we don't want to crash the whole bot
|
||||||
await interaction.editReply(errorMsg('something went wrong'));
|
try {
|
||||||
} else {
|
if (interaction.replied || interaction.deferred) {
|
||||||
await interaction.reply({content: errorMsg(error as Error), ephemeral: true});
|
await interaction.editReply(errorMsg('something went wrong'));
|
||||||
}
|
} else {
|
||||||
|
await interaction.reply({content: errorMsg(error as Error), ephemeral: true});
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {CommandInteraction, MessageActionRow, MessageButton, MessageEmbed} from 'discord.js';
|
import {CommandInteraction, MessageActionRow, MessageButton, MessageEmbed, DiscordAPIError} from 'discord.js';
|
||||||
import getYouTubeID from 'get-youtube-id';
|
import getYouTubeID from 'get-youtube-id';
|
||||||
import getProgressBar from '../utils/get-progress-bar.js';
|
import getProgressBar from '../utils/get-progress-bar.js';
|
||||||
import {prettyTime} from '../utils/time.js';
|
import {prettyTime} from '../utils/time.js';
|
||||||
|
@ -40,13 +40,23 @@ export default class {
|
||||||
* @param interaction
|
* @param interaction
|
||||||
*/
|
*/
|
||||||
async createFromInteraction(interaction: CommandInteraction) {
|
async createFromInteraction(interaction: CommandInteraction) {
|
||||||
this.interaction = interaction;
|
const oldInteraction = this.interaction;
|
||||||
this.currentPage = 1;
|
|
||||||
|
|
||||||
await interaction.reply({
|
this.resetState();
|
||||||
embeds: [this.buildEmbed()],
|
|
||||||
components: this.buildButtons(this.player),
|
this.interaction = interaction;
|
||||||
});
|
|
||||||
|
await Promise.all([
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [this.buildEmbed()],
|
||||||
|
components: this.buildButtons(this.player),
|
||||||
|
}),
|
||||||
|
(async () => {
|
||||||
|
if (oldInteraction) {
|
||||||
|
await oldInteraction.deleteReply();
|
||||||
|
}
|
||||||
|
})(),
|
||||||
|
]);
|
||||||
|
|
||||||
if (!this.refreshTimeout) {
|
if (!this.refreshTimeout) {
|
||||||
this.refreshTimeout = setInterval(async () => this.update(), REFRESH_INTERVAL_MS);
|
this.refreshTimeout = setInterval(async () => this.update(), REFRESH_INTERVAL_MS);
|
||||||
|
@ -58,10 +68,23 @@ export default class {
|
||||||
this.currentPage = 1;
|
this.currentPage = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.interaction?.editReply({
|
try {
|
||||||
embeds: [this.buildEmbed()],
|
await this.interaction?.editReply({
|
||||||
components: this.buildButtons(this.player),
|
embeds: [this.buildEmbed()],
|
||||||
});
|
components: this.buildButtons(this.player),
|
||||||
|
});
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof DiscordAPIError) {
|
||||||
|
// Interaction / message was deleted
|
||||||
|
if (error.code === 10008) {
|
||||||
|
this.resetState();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async pageBack() {
|
async pageBack() {
|
||||||
|
@ -80,6 +103,16 @@ export default class {
|
||||||
await this.update();
|
await this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private resetState() {
|
||||||
|
if (this.refreshTimeout) {
|
||||||
|
clearInterval(this.refreshTimeout);
|
||||||
|
this.refreshTimeout = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentPage = 1;
|
||||||
|
this.interaction = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private buildButtons(player: Player): MessageActionRow[] {
|
private buildButtons(player: Player): MessageActionRow[] {
|
||||||
const queuePageControls = new MessageActionRow()
|
const queuePageControls = new MessageActionRow()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
|
|
Loading…
Reference in a new issue