Added static command field to disable a command in DMs
This commit is contained in:
parent
c01ac7d32f
commit
02a6e256b5
12 changed files with 20 additions and 3 deletions
|
@ -64,6 +64,7 @@ class Command {
|
||||||
static flags = [];
|
static flags = [];
|
||||||
static requires = [];
|
static requires = [];
|
||||||
static slashAllowed = true;
|
static slashAllowed = true;
|
||||||
|
static directAllowed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Command;
|
export default Command;
|
|
@ -12,6 +12,7 @@ class MusicCommand extends Command {
|
||||||
|
|
||||||
static requires = ["sound"];
|
static requires = ["sound"];
|
||||||
static slashAllowed = false;
|
static slashAllowed = false;
|
||||||
|
static directAllowed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MusicCommand;
|
export default MusicCommand;
|
||||||
|
|
|
@ -9,6 +9,7 @@ class SoundboardCommand extends Command {
|
||||||
|
|
||||||
static requires = ["sound"];
|
static requires = ["sound"];
|
||||||
static slashAllowed = false;
|
static slashAllowed = false;
|
||||||
|
static directAllowed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SoundboardCommand;
|
export default SoundboardCommand;
|
||||||
|
|
|
@ -43,6 +43,7 @@ class ChannelCommand extends Command {
|
||||||
static description = "Enables/disables me in a channel (does not work with slash commands)";
|
static description = "Enables/disables me in a channel (does not work with slash commands)";
|
||||||
static arguments = ["[enable/disable]", "{id}"];
|
static arguments = ["[enable/disable]", "{id}"];
|
||||||
static slashAllowed = false;
|
static slashAllowed = false;
|
||||||
|
static directAllowed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ChannelCommand;
|
export default ChannelCommand;
|
||||||
|
|
|
@ -34,6 +34,8 @@ class CommandCommand extends Command {
|
||||||
static description = "Enables/disables a command for a server";
|
static description = "Enables/disables a command for a server";
|
||||||
static aliases = ["cmd"];
|
static aliases = ["cmd"];
|
||||||
static arguments = ["[enable/disable]", "[command]"];
|
static arguments = ["[enable/disable]", "[command]"];
|
||||||
|
static slashAllowed = false;
|
||||||
|
static directAllowed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CommandCommand;
|
export default CommandCommand;
|
||||||
|
|
|
@ -49,6 +49,7 @@ class ServerInfoCommand extends Command {
|
||||||
|
|
||||||
static description = "Gets some info about the server";
|
static description = "Gets some info about the server";
|
||||||
static aliases = ["server"];
|
static aliases = ["server"];
|
||||||
|
static directAllowed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ServerInfoCommand;
|
export default ServerInfoCommand;
|
||||||
|
|
|
@ -38,6 +38,7 @@ class MusicAIOCommand extends Command {
|
||||||
static description = "Handles music playback";
|
static description = "Handles music playback";
|
||||||
static requires = ["sound"];
|
static requires = ["sound"];
|
||||||
static aliases = ["m"];
|
static aliases = ["m"];
|
||||||
|
static directAllowed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MusicAIOCommand;
|
export default MusicAIOCommand;
|
||||||
|
|
|
@ -26,6 +26,7 @@ class SoundboardAIOCommand extends Command {
|
||||||
static description = "Plays a sound effect";
|
static description = "Plays a sound effect";
|
||||||
static requires = ["sound"];
|
static requires = ["sound"];
|
||||||
static aliases = ["sound", "sb"];
|
static aliases = ["sound", "sb"];
|
||||||
|
static directAllowed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SoundboardAIOCommand;
|
export default SoundboardAIOCommand;
|
|
@ -155,6 +155,7 @@ class TagsCommand extends Command {
|
||||||
type: 1,
|
type: 1,
|
||||||
description: "Gets a random tag"
|
description: "Gets a random tag"
|
||||||
}];
|
}];
|
||||||
|
static directAllowed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TagsCommand;
|
export default TagsCommand;
|
||||||
|
|
|
@ -75,6 +75,7 @@ static flags = [{
|
||||||
}];
|
}];
|
||||||
```
|
```
|
||||||
- `slashAllowed`: Specifies whether or not the command is available via slash commands.
|
- `slashAllowed`: Specifies whether or not the command is available via slash commands.
|
||||||
|
- `directAllowed`: Specifies whether or not a command is available in direct messages.
|
||||||
|
|
||||||
## The `run` Function
|
## The `run` Function
|
||||||
The main JS code of your command is specified in the `run` function. This function should return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) of your command output, which is why the `run` function [is an async function by default](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function). The return value inside the `Promise` should be either a string or an object; you should return a string whenever you intend to reply with plain text, or an object if you intend to reply with something else, such as an embed or attachment.
|
The main JS code of your command is specified in the `run` function. This function should return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) of your command output, which is why the `run` function [is an async function by default](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function). The return value inside the `Promise` should be either a string or an object; you should return a string whenever you intend to reply with plain text, or an object if you intend to reply with something else, such as an embed or attachment.
|
|
@ -84,6 +84,9 @@ export default async (client, cluster, worker, ipc, message) => {
|
||||||
const cmd = commands.get(aliased ?? command);
|
const cmd = commands.get(aliased ?? command);
|
||||||
if (!cmd) return;
|
if (!cmd) return;
|
||||||
|
|
||||||
|
// block certain commands from running in DMs
|
||||||
|
if (!cmd.directAllowed && !message.channel.guild) return;
|
||||||
|
|
||||||
// actually run the command
|
// actually run the command
|
||||||
log("log", `${message.author.username} (${message.author.id}) ran classic command ${command}`);
|
log("log", `${message.author.username} (${message.author.id}) ran classic command ${command}`);
|
||||||
const reference = {
|
const reference = {
|
||||||
|
|
|
@ -28,7 +28,8 @@ export async function load(client, cluster, worker, ipc, command, soundStatus, s
|
||||||
aliases: props.aliases,
|
aliases: props.aliases,
|
||||||
params: props.arguments,
|
params: props.arguments,
|
||||||
flags: props.flags,
|
flags: props.flags,
|
||||||
slashAllowed: props.slashAllowed
|
slashAllowed: props.slashAllowed,
|
||||||
|
directAllowed: props.directAllowed
|
||||||
});
|
});
|
||||||
|
|
||||||
const categoryCommands = categories.get(category);
|
const categoryCommands = categories.get(category);
|
||||||
|
@ -69,7 +70,8 @@ export async function update() {
|
||||||
aliases: cmd.aliases,
|
aliases: cmd.aliases,
|
||||||
params: cmd.arguments,
|
params: cmd.arguments,
|
||||||
flags: cmd.flags,
|
flags: cmd.flags,
|
||||||
slashAllowed: cmd.slashAllowed
|
slashAllowed: cmd.slashAllowed,
|
||||||
|
directAllowed: cmd.directAllowed
|
||||||
};
|
};
|
||||||
info.set(name, cmdInfo);
|
info.set(name, cmdInfo);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +79,8 @@ export async function update() {
|
||||||
name,
|
name,
|
||||||
type: 1,
|
type: 1,
|
||||||
description: cmdInfo.description,
|
description: cmdInfo.description,
|
||||||
options: cmdInfo.flags
|
options: cmdInfo.flags,
|
||||||
|
dm_permission: cmdInfo.directAllowed
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return commandArray;
|
return commandArray;
|
||||||
|
|
Loading…
Reference in a new issue