Skip to content

Commit

Permalink
feat: implemention of dm-resolvable
Browse files Browse the repository at this point in the history
  • Loading branch information
Maghish committed Dec 8, 2024
1 parent f1f47fe commit 14c08ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cogs/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cog.addLegacy({
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.SendMessages,
],
dmOnly: "BOTH",
execute(message) {
message.reply(`Pong! ${message.client.ws.ping}ms`);
},
Expand Down
22 changes: 22 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ cog.addEvent({
return;
}

const isDM = message.channel.isDMBased();
const dmOnly = command.dmOnly;

if (dmOnly === "GUILD_ONLY" && !isDM) {
const embed = buildEmbed(
"Command not executable!",
`This command can only be used in DMs! Please use \`${PREFIX}help\` to list all available commands.`,
"Red",
message.client
);
return message.reply({ embeds: [embed] });
}
if (dmOnly === "DM_ONLY" && isDM) {
const embed = buildEmbed(
"Command not executable!",
`This command can only be used in guilds! Please use \`${PREFIX}help\` to list all available commands.`,
"Red",
message.client
);
return message.reply({ embeds: [embed] });
}

if (command.ownerOnly && message.author.id !== modifiedClient.owner) {
const embed = buildEmbed(
"Command not executable!",
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface LegacyCommand {
name: string;
aliases?: string[];
ownerOnly?: boolean;
dmOnly: "BOTH" | "GUILD_ONLY" | "DM_ONLY";
selfPermissions: Discord.PermissionsBitField.Flags[];
userPermissions: Discord.PermissionsBitField.Flags[];
execute(message: Discord.Message, args: string[]): any | Promise<any>;
Expand Down

0 comments on commit 14c08ea

Please sign in to comment.