Archived
2.0.0-beta3 - change console messages appearance + fixed ERROR event bug
This commit is contained in:
1 parent
6e90ce800b
commit
80d8ce7eab
4 files changed
+25
-20
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
# CommandBot
|
# CommandBot
|
||||||
|
|
||||||
**2.0.0-beta2**
|
**2.0.0-beta3**
|
||||||
|
|
||||||
> [IMPORTANT]
|
> [IMPORTANT]
|
||||||
> Upgrading to this version from 1.1.3 may require additional changes in your code since 2.0.0 is not fully backwards compatible
|
> Upgrading to this version from 1.1.3 may require additional changes in your code since 2.0.0 is not fully backwards compatible
|
||||||
@@ -229,10 +229,10 @@ test
|
|||||||
|
|
||||||
Events are emitted using built-in event emitter **(since version 2.0.0)**. You can handle them using _on_ property
|
Events are emitted using built-in event emitter **(since version 2.0.0)**. You can handle them using _on_ property
|
||||||
|
|
||||||
- **ready** - emitted when the client successfully connect to Discord API
|
- **READY** - emitted when the client successfully connect to Discord API
|
||||||
- **message** - emitted for every message sent in any text channel (a [Message](https://discord.js.org/#/docs/main/stable/class/Message) object is passed to the first argument)
|
- **MESSAGE** - emitted for every message sent in any text channel (a [Message](https://discord.js.org/#/docs/main/stable/class/Message) object is passed to the first argument)
|
||||||
- **command** - emitted for every message that gets recognized as a command (a [Message](https://discord.js.org/#/docs/main/stable/class/Message) object is passed to the first argument and a CommandMessageStructure object to the second argument)
|
- **COMMAND** - emitted for every message that gets recognized as a command (a [Message](https://discord.js.org/#/docs/main/stable/class/Message) object is passed to the first argument and a CommandMessageStructure object to the second argument)
|
||||||
- **error** - emitted on permission and command errors (an error object is passed to the first argument)
|
- **ERROR** - emitted on permission and command errors (an error object is passed to the first argument)
|
||||||
> [IMPORTANT]
|
> [IMPORTANT]
|
||||||
> Do not use client.on('message') and client.on('ready') event handler! This handler is a core part of the command system.
|
> Do not use client.on('message') and client.on('ready') event handler! This handler is a core part of the command system.
|
||||||
|
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "commandbot",
|
"name": "commandbot",
|
||||||
"version": "2.0.0-beta2b",
|
"version": "2.0.0-beta3",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "commandbot",
|
"name": "commandbot",
|
||||||
"version": "2.0.0-beta2b",
|
"version": "2.0.0-beta3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^12.5.3"
|
"discord.js": "^12.5.3"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "commandbot",
|
"name": "commandbot",
|
||||||
"version": "2.0.0-beta2b",
|
"version": "2.0.0-beta3",
|
||||||
"description": "A framework that helps you create your own Discord bot easier.",
|
"description": "A framework that helps you create your own Discord bot easier.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
+17
-12
@@ -13,13 +13,13 @@ import { EventEmitter } from "events";
|
|||||||
|
|
||||||
//TYPE DEFINITIONS
|
//TYPE DEFINITIONS
|
||||||
export declare interface Bot {
|
export declare interface Bot {
|
||||||
on(event: "ready", listener: Function): this;
|
on(event: "READY", listener: Function): this;
|
||||||
on(event: "message", listener: (m: Message) => void): this;
|
on(event: "MESSAGE", listener: (m: Message) => void): this;
|
||||||
on(
|
on(
|
||||||
event: "command",
|
event: "COMMAND",
|
||||||
listener: (m: Message, cmdMsg: CommandMessageStructure) => void
|
listener: (m: Message, cmdMsg: CommandMessageStructure) => void
|
||||||
): this;
|
): this;
|
||||||
on(event: "error", listener: (e: any) => void): this;
|
on(event: "ERROR", listener: (e: any) => void): this;
|
||||||
}
|
}
|
||||||
interface ConstructorOptions {
|
interface ConstructorOptions {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -80,7 +80,7 @@ export class Bot extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
async start(port?: number, token?: string): Promise<boolean> {
|
async start(port?: number, token?: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
console.log(`Bot name: ${this.name}`);
|
console.log(`\nBot name: ${this.name}`);
|
||||||
console.log(`Prefix: ${this.commands.prefix} \n`);
|
console.log(`Prefix: ${this.commands.prefix} \n`);
|
||||||
this.token = token || this.token;
|
this.token = token || this.token;
|
||||||
if (this.token === "") {
|
if (this.token === "") {
|
||||||
@@ -89,10 +89,13 @@ export class Bot extends EventEmitter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (port) {
|
if (port) {
|
||||||
console.log(`Creating http server on port ${port}...`);
|
process.stdout.write(
|
||||||
|
`Creating http server on port ${port}... `
|
||||||
|
);
|
||||||
http.createServer().listen(port);
|
http.createServer().listen(port);
|
||||||
|
console.log("✔");
|
||||||
}
|
}
|
||||||
console.log("Starting modules...");
|
process.stdout.write("Starting modules... ");
|
||||||
if (this.messages.help.enabled === true) {
|
if (this.messages.help.enabled === true) {
|
||||||
const helpMsg: Command = new HelpMessage(
|
const helpMsg: Command = new HelpMessage(
|
||||||
this.commands,
|
this.commands,
|
||||||
@@ -101,20 +104,21 @@ export class Bot extends EventEmitter {
|
|||||||
);
|
);
|
||||||
this.commands.add(helpMsg);
|
this.commands.add(helpMsg);
|
||||||
}
|
}
|
||||||
console.log("Connecting to Discord...");
|
console.log("✔");
|
||||||
|
process.stdout.write("Connecting to Discord... ");
|
||||||
if (await this.client.login(this.token)) {
|
if (await this.client.login(this.token)) {
|
||||||
this.client.on("ready", () => {
|
this.client.on("ready", () => {
|
||||||
this.emit("ready");
|
console.log("✔\n");
|
||||||
|
this.emit("READY");
|
||||||
});
|
});
|
||||||
this.client.on("message", async (m) => {
|
this.client.on("message", async (m) => {
|
||||||
const cmdMsg: CommandMessageStructure | null =
|
const cmdMsg: CommandMessageStructure | null =
|
||||||
this.commands.fetch(m);
|
this.commands.fetch(m);
|
||||||
if (cmdMsg?.command) {
|
if (cmdMsg?.command) {
|
||||||
this.emit("command", [m, cmdMsg]);
|
this.emit("COMMAND", [m, cmdMsg]);
|
||||||
try {
|
try {
|
||||||
await cmdMsg.command.start(m, cmdMsg.arguments);
|
await cmdMsg.command.start(m, cmdMsg.arguments);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.emit("error", [e]);
|
|
||||||
if (e instanceof PermissionsError) {
|
if (e instanceof PermissionsError) {
|
||||||
this.messages.system.send(
|
this.messages.system.send(
|
||||||
"PERMISSION",
|
"PERMISSION",
|
||||||
@@ -136,6 +140,7 @@ export class Bot extends EventEmitter {
|
|||||||
);
|
);
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
this.emit("ERROR", [e]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (cmdMsg) {
|
} else if (cmdMsg) {
|
||||||
@@ -145,7 +150,7 @@ export class Bot extends EventEmitter {
|
|||||||
m.channel
|
m.channel
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.emit("message", [m]);
|
this.emit("MESSAGE", [m]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user