Fixed some issues
This commit is contained in:
parent
c418ba4d84
commit
bebaf30d16
3 changed files with 3 additions and 193 deletions
10
README.md
10
README.md
|
@ -4,7 +4,7 @@ Discord bot client based upon Discord.js
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Download the latest version from the [releases page](https://github.com/GetGravitySoft/vylbot-core/releases).
|
Download the latest version from the [releases page](https://gitlab.vylpes.com/Vylpes/vylbot-core/-/releases).
|
||||||
|
|
||||||
Copy the config template file and fill in the strings.
|
Copy the config template file and fill in the strings.
|
||||||
|
|
||||||
|
@ -38,13 +38,7 @@ const client = new vylbot.client(config);
|
||||||
client.start();
|
client.start();
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [docs](https://github.com/GetGravitySoft/vylbot-core/blob/main/docs/index.md) for more information on how to use vylbot-core
|
See the [docs](https://gitlab.vylpes.com/Vylpes/vylbot-core/-/wikis/home) for more information on how to use vylbot-core
|
||||||
|
|
||||||
## VylBot Essentials
|
|
||||||
|
|
||||||
Want basic commands to add to your bot? Checkout [VylBot Essentials](https://github.com/GetGravitySoft/vylbot-essentials)!
|
|
||||||
|
|
||||||
Latest release: `1.0.0` on `3rd November 2020`
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
184
docs/index.md
184
docs/index.md
|
@ -1,184 +0,0 @@
|
||||||
# VylBot Core Documentation
|
|
||||||
|
|
||||||
Welcome to the VylBot Core documentation. In this file we will explain how to setup and use VylBot Core in your project.
|
|
||||||
|
|
||||||
## Contents
|
|
||||||
|
|
||||||
1. Initial Setup
|
|
||||||
2. Configuring the client
|
|
||||||
3. Creating a command
|
|
||||||
4. Handling an event
|
|
||||||
5. Configuring command configs
|
|
||||||
|
|
||||||
## 1. Initial Setup
|
|
||||||
|
|
||||||
To setup the package, download it from `npm`
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd <project-folder>
|
|
||||||
npm install vylbot-core
|
|
||||||
```
|
|
||||||
|
|
||||||
Add to your .js file
|
|
||||||
|
|
||||||
```js
|
|
||||||
const vylbot = require('vylbot-core');
|
|
||||||
const config = require('./config.json');
|
|
||||||
|
|
||||||
const client = new vylbot.client(config);
|
|
||||||
client.start();
|
|
||||||
```
|
|
||||||
|
|
||||||
## 2. Configuring the client
|
|
||||||
|
|
||||||
When creating a new `vylbot.client` object you need to pass through some json configuration. This can be either from a .json file or directly written.
|
|
||||||
|
|
||||||
> **Note:** We recommend using a .json file and adding it to your `.gitignore` file to prevent accidentally publishing your bot token.
|
|
||||||
|
|
||||||
An example configuration:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"token": "<YOUR-BOT-TOKEN>",
|
|
||||||
"prefix": "!",
|
|
||||||
"commands": [
|
|
||||||
"commands"
|
|
||||||
],
|
|
||||||
"events": [
|
|
||||||
"events"
|
|
||||||
],
|
|
||||||
"cmdconfig": "cmdconfig.json"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
- Make sure the folders that you set for `commands` and `events` exist and are at your project's current working directory.
|
|
||||||
- Make sure the file set in `cmdconfig` exists and contains json data for the commands (see below)
|
|
||||||
|
|
||||||
## 3. Creating a command
|
|
||||||
|
|
||||||
A basic command goes as follows:
|
|
||||||
|
|
||||||
```js
|
|
||||||
// commands/test.js
|
|
||||||
const { command } = require('vylbot-core');
|
|
||||||
|
|
||||||
class test extends command {
|
|
||||||
constructor() {
|
|
||||||
super("test");
|
|
||||||
super.description = "Test description";
|
|
||||||
super.category = "general";
|
|
||||||
super.configs = "link";
|
|
||||||
super.roles = "Moderator";
|
|
||||||
super.roles = "Admin";
|
|
||||||
super.users = "<ID-HERE>";
|
|
||||||
}
|
|
||||||
|
|
||||||
test(context) {
|
|
||||||
context.message.channel.send("Hello there, " + context.config.link);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = test;
|
|
||||||
```
|
|
||||||
|
|
||||||
1. You create a class and export it using `module.exports` and make it extend the vylbot's `command` class.
|
|
||||||
2. In the `constructor()` you need to call `super(run)`, replacing `run` with a string of the name of the method which will run when the command runs.
|
|
||||||
3. Call any of the `super` variables to give it some description, the current ones you can use are: `description`, `category`, `usage`
|
|
||||||
4. If you want the command to only be allowed to run by people with a role, set the role name in `super.roles`
|
|
||||||
|
|
||||||
> **Note:** You can set more than one role to be required by setting `super.roles` again.
|
|
||||||
|
|
||||||
5. If you want the command to only be ran by specific users, set their ID in `super.users`
|
|
||||||
|
|
||||||
> **Note:** You can set more than one user to be required by settubg `super.users` again.
|
|
||||||
|
|
||||||
6. If you want the command to require a variable in the config, set the name in `super.configs`
|
|
||||||
|
|
||||||
> **Note:** You can set more than one role to be required by setting `super.configs` again.
|
|
||||||
|
|
||||||
7. Create a method using the name you set in `super(run)`, with the `context` as its parameter.
|
|
||||||
|
|
||||||
The `context` parameter will be a JSON object of:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"command": "<Command Name>",
|
|
||||||
"arguments": "<Command Arguments>",
|
|
||||||
"client": "<Bot Client Object",
|
|
||||||
"message": "Discord.js Message Object",
|
|
||||||
"config": "The command's config (if any)"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The command's config will be stored under the command's name, for example, if a command called `test` has set `super.configs = "link"`, it will be set in the config as `test.link`.
|
|
||||||
|
|
||||||
## 4. Handling an event
|
|
||||||
|
|
||||||
A basic event handling goes as follows:
|
|
||||||
|
|
||||||
```js
|
|
||||||
// events/message.js
|
|
||||||
const { event } = require('vylbot-core');
|
|
||||||
|
|
||||||
class message extends event {
|
|
||||||
constructor() {
|
|
||||||
super("message");
|
|
||||||
}
|
|
||||||
|
|
||||||
message(message) {
|
|
||||||
console.log("Message received: " + message.content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = message;
|
|
||||||
```
|
|
||||||
|
|
||||||
1. You create a class and export it using `module.exports` and make it extend the vylbot's `event` class.
|
|
||||||
2. In the `constructor()` you need to call `super(run)`, replacing `run` with a string of the name of the method which will run when the event gets triggered.
|
|
||||||
3. Create a method using the name you set in `super(run)`, with the parameters being as per your event's paramaters in the discord.js documentation.
|
|
||||||
|
|
||||||
> **Note:** The name of the event file will determine what event it will be triggered on. For example, if you want to have an event trigger everytime a message is sent, put into your event folder a file called `message.js` and follow the steps above.
|
|
||||||
|
|
||||||
## 5. Configuring command configs
|
|
||||||
|
|
||||||
The command config json (specified in the main config's `cmdconfig` variable) contiains all the configuration set for the commands.
|
|
||||||
|
|
||||||
The syntax is as follows:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"Command": {
|
|
||||||
"Variable": "Value"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Command:** The name of the command, such as `ban.js` command would be `ban`.
|
|
||||||
- **Variable:** The variable name set in the command, this would be one for every `super.configs` in the command's constructor.
|
|
||||||
- **Value:** The value for the command.
|
|
||||||
|
|
||||||
An example would be:
|
|
||||||
|
|
||||||
```js
|
|
||||||
// ban.js
|
|
||||||
|
|
||||||
class ban extends Command {
|
|
||||||
constructor() {
|
|
||||||
super("ban");
|
|
||||||
super.configs = "modrole";
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Would have in the command config file:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"ban": {
|
|
||||||
"modrole": "Moderators"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "vylbot-core",
|
"name": "vylbot-core",
|
||||||
"version": "1.0.4",
|
"version": "20.0.0",
|
||||||
"description": "A discord client based upon discord.js",
|
"description": "A discord client based upon discord.js",
|
||||||
"main": "./src/index",
|
"main": "./src/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Reference in a new issue