Archived
1.1.0 -> permissionCheck property
This commit is contained in:
1 parent
fc1174de66
commit
4880e47f34
4 files changed
+12
-5
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# CommandBot
|
||||
**1.0.0**
|
||||
**1.1.0**
|
||||
|
||||
Discord.js framework that helps you build your own Discord bot.
|
||||
|
||||
@@ -80,6 +80,7 @@ The main object of this library has the following properties
|
||||
- **visible** - *boolean* - show command in the *help message* (optional, defaults to *true*)
|
||||
- **description** - *string* - command description shown in the *help message* (optional)
|
||||
- **usage** - *string* - command usage description shown in the *help message* (optional)
|
||||
- **permissionCheck** - *"ALL" | "ANY"* - specifies if the caller has to have all of the specified permissions or any of that (optional, default value: "ANY")
|
||||
- **permissions** - *[PermissionResolvable](https://discord.js.org/#/docs/main/stable/typedef/PermissionResolvable)* - permissions needed to run the command (optional)
|
||||
- **aliases** - *string | string[]* - other words that can trigger the command with prefix (optional)
|
||||
- **keywords** - *string | string[]* - other words that can trigger the command without prefix (optional)
|
||||
@@ -207,6 +208,8 @@ Each message can be customized using these properties
|
||||
- **accentColor** - *[ColorResolvable](https://discord.js.org/#/docs/main/stable/typedef/ColorResolvable)* - color of the embedded content
|
||||
- **showTimestamp** - *boolean* - show time and date at the bottom of the embedded content
|
||||
- **footer** - *string* - footer of the embedded content
|
||||
|
||||
The *messages.system* also contains a *deleteTimeout* property. It specifies the time (in ms) after which a system message will be deleted. Set it to *Infinity* to never delete messages (default value).
|
||||
## Complete example
|
||||
```javascript
|
||||
import { Bot, Command } from 'commandbot';
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "commandbot",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "commandbot",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.5.3"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "commandbot",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"description": "A framework that helps you create your own Discord bot easier.",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
||||
+5
-1
@@ -8,6 +8,7 @@ interface CommandBuilder {
|
||||
keywords?: string[] | string,
|
||||
description?: string,
|
||||
usage?: string,
|
||||
permissionCheck?: PermissionCheckTypes,
|
||||
permissions?: PermissionResolvable,
|
||||
visible?: boolean
|
||||
function: (message?: Message, cmdArguments?: string[]) => void | string | MessageEmbed;
|
||||
@@ -18,6 +19,7 @@ interface CommandMessageStructure {
|
||||
command: Command | null
|
||||
}
|
||||
type GetMode = 'ALL' | 'PREFIX' | 'NO_PREFIX';
|
||||
type PermissionCheckTypes = 'ALL' | 'ANY';
|
||||
|
||||
//ERROR CLASSES
|
||||
class PermissionsError {
|
||||
@@ -39,6 +41,7 @@ class Command {
|
||||
keywords: string[];
|
||||
description: string;
|
||||
usage: string;
|
||||
permissionCheck: PermissionCheckTypes;
|
||||
permissions: Permissions;
|
||||
visible: boolean;
|
||||
private function: (message?: Message, cmdArguments?: string[]) => void | string | MessageEmbed;
|
||||
@@ -49,13 +52,14 @@ class Command {
|
||||
this.keywords = Command.processPhrase(options.keywords);
|
||||
this.description = options.description || "No description";
|
||||
this.usage = options.usage || "";
|
||||
this.permissionCheck = options.permissionCheck == 'ALL' || options.permissionCheck == 'ANY' ? options.permissionCheck : "ANY";
|
||||
this.permissions = new Permissions(options.permissions || 0);
|
||||
this.visible = options.visible != undefined ? options.visible : true;
|
||||
this.function = options.function;
|
||||
}
|
||||
async start(message?: Message, cmdArguments?: string[]) : Promise<void> {
|
||||
const memberPermissions : Readonly<Permissions> = message?.member?.permissions || new Permissions(0);
|
||||
if(memberPermissions.has(this.permissions, true)) {
|
||||
if(this.permissionCheck == 'ALL' ? memberPermissions.has(this.permissions, true) : memberPermissions.any(this.permissions, true)) {
|
||||
const fnResult = await this.function(message, cmdArguments);
|
||||
if(typeof fnResult == 'string') {
|
||||
await message?.reply(fnResult);
|
||||
|
||||
Reference in new issue
Block a user