-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy patheditRoleSelectMenu.ts
More file actions
92 lines (84 loc) · 3.17 KB
/
editRoleSelectMenu.ts
File metadata and controls
92 lines (84 loc) · 3.17 KB
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
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
* Copyright © 2026 BotForge
*/
import { ActionRowBuilder, ContainerBuilder, RoleSelectMenuBuilder } from "discord.js"
import { ArgType, NativeFunction } from "../../structures"
import { buildComponent } from "../../functions/components"
export default new NativeFunction({
name: "$editRoleSelectMenu",
version: "2.2.0",
description: "Edits a role select menu",
unwrap: true,
brackets: true,
args: [
{
name: "old custom ID",
description: "The custom id of the menu to edit",
rest: false,
required: true,
type: ArgType.String,
},
{
name: "new custom ID",
description: "The new custom id to use for this menu",
rest: false,
required: true,
type: ArgType.String,
},
{
name: "placeholder",
description: "The placeholder to use for the menu",
rest: false,
type: ArgType.String,
},
{
name: "disabled",
description: "Whether to keep this menu disabled",
type: ArgType.Boolean,
rest: false,
},
{
name: "min values",
description: "The min values to choose for the menu",
rest: false,
type: ArgType.Number,
},
{
name: "max values",
description: "The max values to choose for the menu",
rest: false,
type: ArgType.Number,
},
{
name: "default roles",
rest: true,
type: ArgType.String,
description: "The default selected roles of the menu"
}
],
execute(ctx, [old, id, placeholder, disabled, min, max, roles]) {
for (let i = 0, len = ctx.container.components.length;i < len;i++) {
const comp = ctx.container.components[i]
const comps = comp instanceof ContainerBuilder
? comp.components.map((x) => buildComponent(x.toJSON()))
: ("components" in comp ? comp.components : undefined)
if (!comps) continue
for (let n = 0, len = comps.length;n < len;n++) {
const row = comps[n]
const menu = row instanceof ActionRowBuilder ? row.components[0] : row
if (menu instanceof RoleSelectMenuBuilder && menu.data.custom_id === old) {
menu.setCustomId(id)
if (placeholder) menu.setPlaceholder(placeholder)
if (typeof disabled === "boolean") menu.setDisabled(disabled)
if (typeof min === "number") menu.setMinValues(min)
if (typeof max === "number") menu.setMaxValues(max)
if (roles.length) menu.setDefaultRoles(roles.filter(Boolean))
if (comp instanceof ContainerBuilder) comp.spliceComponents(n, 1, new ActionRowBuilder().addComponents(menu))
return this.success()
}
}
}
return this.success()
},
})