Skip to content

Commit

Permalink
much nicer warnUser code
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Nov 19, 2023
1 parent 69d81d1 commit 667046d
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/helpers/warnUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,18 @@ export async function warnUser(
};

// make ephemeral if possible
if (!(interaction instanceof Message)) {
if (interaction instanceof Message) {
const reply = await interaction.reply(args);
console.log("message reply");
reply.deleteButton();
} else {
args.ephemeral = true;
args.fetchReply = true;
}

let reply: Message;
try {
reply = await (interaction as ChatInputCommandInteraction).reply(args);
} catch {
try {
// check if deferred
reply = await (interaction as ChatInputCommandInteraction).editReply(args);
} catch {
// follow up if original message not found
reply = await (interaction as ChatInputCommandInteraction).followUp(args);
}
// no need for delete button because we force ephemeral always
await (interaction as ChatInputCommandInteraction)
.reply(args)
.catch(async () => await (interaction as ChatInputCommandInteraction).ephemeralReply(args));
}

if (interaction instanceof Message) reply.deleteButton();
}

/**
Expand Down

0 comments on commit 667046d

Please sign in to comment.