/
ButtonHandler.ts
140 lines (139 loc) · 3.34 KB
/
ButtonHandler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { ButtonInteraction, Message, PermissionsString, User } from 'discord.js';
import { Precondition } from '../structures/Precondition';
import { AmethystClient } from '../structures/AmethystClient';
/**
* Options of a button handler
*/
export type ButtonHandlerOptions = {
/**
* custom ID of the button
*
* This is supposed to be the id of the button you want to match with
* @type string
*/
customId: string;
/**
* Permissions the user needs to press the button
*
* @type PermissionString[]
*/
permissions?: PermissionsString[];
/**
* Permissions the client needs in the server to press the button
*
* @type PermissionString[]
*/
clientPermissions?: PermissionsString[];
/**
* Preconditions of the button
*
* @type Precondition[]
*/
preconditions?: Precondition[];
/**
* Additionnal custom ids of other buttons that can match the handler
*
* @type string[]
*/
identifiers?: string[];
};
export enum ButtonDeniedCode {
/**
* The user is missing permissions
*/
MissingPerms = 'User is missing permissions',
/**
* Client is missing permissions
*/
ClientMissingPerms = 'Client is missing permissions',
/**
* Custom precondition stopped the button
*/
CustomPrecondition = 'Custom precondition',
/**
* The button can't be executed in a server
*/
DMOnly = 'Direct messages only',
/**
* The button can't be executed in a not-nsfw channel
*/
NsfwOnly = 'Nsfw channel only',
/**
* The button can't be executed in direct messages
*/
GuildOnly = 'Guild only',
/**
* The system can't determine the type of the channel
*/
UnknownChannelType = 'Unknown channel type'
}
export type ButtonDenied = {
/**
* Optionnal message of the denietion of the button
*/
message?: string;
/**
* Button that triggered the denietion
*/
button: ButtonInteraction;
/**
* Additional datas
*/
metadata?: {
/**
* Optionnal code to give a unique ID to the denietion
*/
code?: ButtonDeniedCode | string | number;
/**
* Permissions in case of missing permission denietion
*/
permissions?: {
/**
* Permissions the client or the user has among the needed permissions
*/
got: PermissionsString[];
/**
* Permissions needed to run the command
*/
need: PermissionsString[];
/**
* Permissions missing to the client or the user
*/
missing: PermissionsString[];
};
[key: string | number]: any;
};
/**
* User of the interaction
*/
user: User;
};
/**
* Method of the runner
*/
export type ButtonHandlerRun = (options: {
/**
* Button that triggered the handler
*
* @type ButtonInteraction
*/
button: ButtonInteraction;
/**
* User that used the button
*
* @type User
*/
user: User;
/**
* Message where the button is used
*
* @type Message
*/
message: Message;
/**
* Client of the interaction
*
* @type AmethystClient
*/
client: AmethystClient;
}) => void | unknown;