Skip to content

Commit

Permalink
feat: global ephemeral replies for system messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirasaki committed May 19, 2023
1 parent e3c67dc commit 5259ca9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
15 changes: 12 additions & 3 deletions src/handlers/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ const checkCommandCanExecute = (client, interaction, clientCmd) => {
// Check if the command is currently disabled
// Needed 'cuz it takes a while for CommandInteractions to sync across server
if (enabled === false) {
interaction.reply({ content: `${ emojis } ${ member }, this command is currently disabled. Please try again later.` });
interaction.reply({
content: `${ emojis } ${ member }, this command is currently disabled. Please try again later.`,
ephemeral: true
});
return false;
}

Expand All @@ -517,7 +520,10 @@ const checkCommandCanExecute = (client, interaction, clientCmd) => {
const missingPerms = hasChannelPerms(client.user.id, channel, clientPerms);

if (missingPerms !== true) {
interaction.reply({ content: `${ emojis.error } ${ member }, this command can't be executed because I lack the following permissions in ${ channel }\n${ emojis.separator } ${ resolvePermissionArray(missingPerms).join(', ') }` });
interaction.reply({
content: `${ emojis.error } ${ member }, this command can't be executed because I lack the following permissions in ${ channel }\n${ emojis.separator } ${ resolvePermissionArray(missingPerms).join(', ') }`,
ephemeral: true
});
return false;
}
}
Expand All @@ -527,7 +533,10 @@ const checkCommandCanExecute = (client, interaction, clientCmd) => {
const missingPerms = hasChannelPerms(member.user.id, channel, userPerms);

if (missingPerms !== true) {
interaction.reply({ content: `${ emojis.error } ${ member }, this command can't be executed because you lack the following permissions in ${ channel }:\n${ emojis.separator } ${ resolvePermissionArray(missingPerms).join(', ') }` });
interaction.reply({
content: `${ emojis.error } ${ member }, this command can't be executed because you lack the following permissions in ${ channel }:\n${ emojis.separator } ${ resolvePermissionArray(missingPerms).join(', ') }`,
ephemeral: true
});
return false;
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/listeners/interaction/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const checkInteractionAvailability = (interaction) => {
// Planning on adding support later down the road
if (!interaction.inGuild()) {
if (interaction.isRepliable()) {
interaction.reply({ content: `${ emojis.error } ${ member }, I don't currently support DM interactions. Please try again in a server.` });
interaction.reply({
content: `${ emojis.error } ${ member }, I don't currently support DM interactions. Please try again in a server.`,
ephemeral: true
});
}
return false;
}
Expand Down Expand Up @@ -71,9 +74,12 @@ const runCommand = (client, interaction, activeId, cmdRunTimeStart) => {
if (!dynamicCmd) return; // Should be ignored
}

// Check if we can reply to this interaction
const clientCanReply = interaction.isRepliable();

// Check for late API changes
if (!clientCmd) {
interaction.reply({
if (clientCanReply) interaction.reply({
content: `${ emojis.error } ${ member }, this command currently isn't available.`,
ephemeral: true
});
Expand All @@ -85,8 +91,6 @@ const runCommand = (client, interaction, activeId, cmdRunTimeStart) => {
const { data } = clientCmd;

// Return if we can't reply to the interaction
const clientCanReply = interaction.isRepliable();

if (!clientCanReply) {
logger.debug(`Interaction returned - Can't reply to interaction\nCommand: ${ data.name }\nServer: ${ guild.name }\nChannel: #${ channel.name }\nMember: ${ member }`);
return;
Expand All @@ -106,7 +110,10 @@ const runCommand = (client, interaction, activeId, cmdRunTimeStart) => {
const onCooldown = throttleCommand(clientCmd, interaction);

if (onCooldown !== false) {
interaction.reply({ content: onCooldown.replace('{{user}}', `${ member }`) });
interaction.reply({
content: onCooldown.replace('{{user}}', `${ member }`),
ephemeral: true
});
return;
}
}
Expand Down

0 comments on commit 5259ca9

Please sign in to comment.