added the option to disable message command (prefix)

This commit is contained in:
mmacierzanka committed 2021-08-10 02:44:08 +02:00
1 parent 0a9cdb7bde
commit 9e78438d0a
4 files changed
+14 -6

No files matched your search

+4 -1
View File
@@ -157,7 +157,10 @@ export class Bot extends EventEmitter {
if (cmdMsg) {
this.emit("COMMAND", m, cmdMsg);
await cmdMsg.command.start(m, cmdMsg.parameters);
} else if (m.content.startsWith(this.commands.prefix)) {
} else if (
this.commands.prefix &&
m.content.startsWith(this.commands.prefix)
) {
this.emit("MESSAGE", m);
await this.messages.system.send(
"NOT_FOUND",
+3 -2
View File
@@ -12,10 +12,10 @@ import { CommandMessageStructure, PhraseOccurrenceData } from "./types.js";
export class CommandManager {
list: Command[];
prefix: string;
prefix?: string;
argumentSeparator: string;
constructor(prefix: string, argumentSeparator?: string) {
constructor(prefix?: string, argumentSeparator?: string) {
this.list = [];
this.prefix = prefix;
this.argumentSeparator = argumentSeparator || ",";
@@ -85,6 +85,7 @@ export class CommandManager {
* @returns *CommandMessagesStructure* | *null*
*/
fetchFromMessage(message: Message): CommandMessageStructure | null {
if (!this.prefix) return null;
if (!message.author.bot && message.content.startsWith(this.prefix)) {
const content = message.content.replace(this.prefix, "");
const name = content.split(" ")[0];
+6 -2
View File
@@ -41,7 +41,9 @@ export class HelpMessage extends Command {
if (cmd.usage)
helpMsg.addField(
"Usage:",
`${cmdManager.prefix}${cmd.name} ${cmd.usage}`,
`${cmdManager.prefix || "/"}${cmd.name} ${
cmd.usage
}`,
false
);
if (
@@ -79,7 +81,9 @@ export class HelpMessage extends Command {
cmdManager.list.map((c) => {
if (c.visible) {
helpMsg.addField(
`${cmdManager.prefix}${c.name} ${c.usage}`,
`${cmdManager.prefix || "/"}${c.name} ${
c.usage
}`,
c.description,
false
);
+1 -1
View File
@@ -10,7 +10,7 @@ import type { Command } from "./Command.js";
export interface InitOptions {
name: string;
prefix: string;
prefix?: string;
argumentSeparator?: string;
clientOptions?: ClientOptions;
token: string;