Archived
added the option to disable message command (prefix)
This commit is contained in:
1 parent
0a9cdb7bde
commit
9e78438d0a
4 files changed
+14
-6
No files matched your search
+4
-1
@@ -157,7 +157,10 @@ export class Bot extends EventEmitter {
|
|||||||
if (cmdMsg) {
|
if (cmdMsg) {
|
||||||
this.emit("COMMAND", m, cmdMsg);
|
this.emit("COMMAND", m, cmdMsg);
|
||||||
await cmdMsg.command.start(m, cmdMsg.parameters);
|
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);
|
this.emit("MESSAGE", m);
|
||||||
await this.messages.system.send(
|
await this.messages.system.send(
|
||||||
"NOT_FOUND",
|
"NOT_FOUND",
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ import { CommandMessageStructure, PhraseOccurrenceData } from "./types.js";
|
|||||||
|
|
||||||
export class CommandManager {
|
export class CommandManager {
|
||||||
list: Command[];
|
list: Command[];
|
||||||
prefix: string;
|
prefix?: string;
|
||||||
argumentSeparator: string;
|
argumentSeparator: string;
|
||||||
|
|
||||||
constructor(prefix: string, argumentSeparator?: string) {
|
constructor(prefix?: string, argumentSeparator?: string) {
|
||||||
this.list = [];
|
this.list = [];
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
this.argumentSeparator = argumentSeparator || ",";
|
this.argumentSeparator = argumentSeparator || ",";
|
||||||
@@ -85,6 +85,7 @@ export class CommandManager {
|
|||||||
* @returns *CommandMessagesStructure* | *null*
|
* @returns *CommandMessagesStructure* | *null*
|
||||||
*/
|
*/
|
||||||
fetchFromMessage(message: Message): CommandMessageStructure | null {
|
fetchFromMessage(message: Message): CommandMessageStructure | null {
|
||||||
|
if (!this.prefix) return null;
|
||||||
if (!message.author.bot && message.content.startsWith(this.prefix)) {
|
if (!message.author.bot && message.content.startsWith(this.prefix)) {
|
||||||
const content = message.content.replace(this.prefix, "");
|
const content = message.content.replace(this.prefix, "");
|
||||||
const name = content.split(" ")[0];
|
const name = content.split(" ")[0];
|
||||||
|
|||||||
+6
-2
@@ -41,7 +41,9 @@ export class HelpMessage extends Command {
|
|||||||
if (cmd.usage)
|
if (cmd.usage)
|
||||||
helpMsg.addField(
|
helpMsg.addField(
|
||||||
"Usage:",
|
"Usage:",
|
||||||
`${cmdManager.prefix}${cmd.name} ${cmd.usage}`,
|
`${cmdManager.prefix || "/"}${cmd.name} ${
|
||||||
|
cmd.usage
|
||||||
|
}`,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
@@ -79,7 +81,9 @@ export class HelpMessage extends Command {
|
|||||||
cmdManager.list.map((c) => {
|
cmdManager.list.map((c) => {
|
||||||
if (c.visible) {
|
if (c.visible) {
|
||||||
helpMsg.addField(
|
helpMsg.addField(
|
||||||
`${cmdManager.prefix}${c.name} ${c.usage}`,
|
`${cmdManager.prefix || "/"}${c.name} ${
|
||||||
|
c.usage
|
||||||
|
}`,
|
||||||
c.description,
|
c.description,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import type { Command } from "./Command.js";
|
|||||||
|
|
||||||
export interface InitOptions {
|
export interface InitOptions {
|
||||||
name: string;
|
name: string;
|
||||||
prefix: string;
|
prefix?: string;
|
||||||
argumentSeparator?: string;
|
argumentSeparator?: string;
|
||||||
clientOptions?: ClientOptions;
|
clientOptions?: ClientOptions;
|
||||||
token: string;
|
token: string;
|
||||||
|
|||||||
Reference in new issue
Block a user