This repository has been archived on 2023-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
vylbot-core/README.md

115 lines
3.2 KiB
Markdown
Raw Permalink Normal View History

2020-10-20 10:59:53 +01:00
# VylBot Core
Discord bot client based upon Discord.js
## Installation
2021-02-01 17:49:08 +00:00
Download the latest version from the [releases page](https://gitlab.vylpes.com/Vylpes/vylbot-core/-/releases).
2020-10-20 10:59:53 +01:00
2021-07-20 17:55:31 +01:00
Copy the config template file and fill in the values.
```env
BOT_TOKEN={TOKEN}
BOT_PREFIX=v!
FOLDERS_COMMANDS=commands
FOLDERS_EVENTS=events
2021-09-22 19:54:49 +01:00
COMMANDS_DISABLED=
2021-09-24 18:46:49 +01:00
COMMANDS_DISABLED_MESSAGE=This command is disabled.
2020-10-20 10:59:53 +01:00
```
2021-09-22 19:54:49 +01:00
* **BOT_TOKEN:** Your bot's token, replace {TOKEN} with your bot token.
* **BOT_PREFIX:** The command prefix.
* **FOLDERS_COMMANDS:** The folder which contains your commands.
* **FOLDERS_EVENTS:** The folder which contains your events.
* **COMMANDS_DISABLED:** List of command file names that won't run, separated by commas.
2021-09-24 18:46:49 +01:00
* **COMMANDS_DISABLED_MESSAGE:** The message which is replied to the user who tries to run a disabled command.
2021-07-20 17:55:31 +01:00
Make sure that you **DO NOT** put your .env file into VCS!
2020-10-20 10:59:53 +01:00
## Usage
Implement the client using something like:
2021-07-20 17:55:31 +01:00
```ts
// bot.ts
import { CoreClient } from "vylbot-core";
2020-10-20 10:59:53 +01:00
2021-07-20 17:55:31 +01:00
const client = new CoreClient();
2020-10-20 10:59:53 +01:00
client.start();
```
2021-07-20 17:55:31 +01:00
### Writing Commands
The code below will reply to the user with 'PONG' when they type {PREFIX}ping
```ts
// Ping.ts
import { Command, ICommandContext } from "vylbot-core";
2021-09-26 14:13:09 +01:00
export default class Ping extends Command {
2021-07-20 17:55:31 +01:00
constructor() {
super();
this._roles = [ "Moderator" ];
this._category = "General";
}
public override execute(context: ICommandContext) {
context.message.reply('PONG');
}
}
```
* **roles**: An array containing what roles the user needs in order to run the command.
* **category**: The category the role is part of, useful for categorising commands together in a help command.
The `context` parameter contains the following:
* **name**: The command name
* **args**: An array of arguments supplied with the command
* **message**: The Discord Message object for the command message sent
### Writing Events
The code below will log to the console 'Member Joined: {USERNAME}' when a member joins a server the bot is in
```ts
// Moderation.ts
import { Event } from "vylbot-core";
import { GuildMember } from "discord.js";
export class Moderation extends Event {
public override guildMemberAdd(member: GuildMember) {
console.log(`Member Joined: ${member.tag}`);
}
}
```
The following events are supported:
* channelCreate(channel: Channel)
* channelDelete(channel: Channel | PartialDMChannel)
* channelUpdate(oldChannel: Channel, newChannel: Channel)
* guildBanAdd(guild: Guild, user: User)
* guildBanRemove(guild: Guild, user: User)
* guildCreate(guild: Guild)
* guildMemberAdd(member: GuildMember)
* guildMemberRemove(member: GuildMember | PartialGuildMember)
* guildMemberUpdate(oldMember: GuildMember | PartialGuildMember, newMember: GuildMember)
* message(message: Message)
* messageDelete(message: Message | PartialMessage)
* messageUpdate(oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage)
2021-07-22 17:52:36 +01:00
* ready()
2021-07-20 17:55:31 +01:00
All parameters are supplied from discord.js
2020-11-03 13:50:55 +00:00
2020-10-20 10:59:53 +01:00
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
We will not merge pull requests unless all checks pass and at least one of the repo members approves it.
See CONTRIBUTING.md for more details.