Repository navigation
Expand file tree
/
Copy pathallRoles.js
More file actions
109 lines (95 loc) · 2.93 KB
/
Copy pathallRoles.js
File metadata and controls
109 lines (95 loc) · 2.93 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { SlashCommandBuilder } from "@discordjs/builders";
import {
ActionRowBuilder,
EmbedBuilder,
ButtonStyle,
Colors,
} from "discord.js";
import {
channelSend,
fetchChannel,
fetchGuild,
fetchMember,
interactionReply,
} from "ewilib";
import { createButton } from "./utils.js";
import { COMMONS } from "../classes/commons.js";
import { PERSONALITY } from "../classes/personality.js";
export const allRolesButtonHandler = async (interaction) => {
const { client, customId, guildId, member, user } = interaction;
const personality = PERSONALITY.getPersonality().allRoles;
const perso = personality.role;
const commons = COMMONS.fetchFromGuildId(guildId);
const roleName = customId.split("_")[1];
const allRoleId = commons.allRoles[roleName];
//give requested role
const guild = await fetchGuild(client, guildId);
const guildMember = !member
? member
: await fetchMember(guild.members, user.id); //get in cache new members
if (guildMember) {
if (!guildMember.roles.cache.has(allRoleId)) {
await guildMember.roles.add(allRoleId);
interactionReply(interaction, perso.added);
} else {
await guildMember.roles.remove(allRoleId);
interactionReply(interaction, perso.removed);
}
} else {
interactionReply(interaction, perso.errorCantFetchMember);
}
};
const command = new SlashCommandBuilder()
.setName(PERSONALITY.getPersonality().allRoles.name)
.setDescription(PERSONALITY.getPersonality().allRoles.description)
.setDefaultMemberPermissions(0x0000010000000000);
const action = async (interaction) => {
const perso = PERSONALITY.getPersonality().allRoles;
const currentServer = COMMONS.fetchFromGuildId(interaction.guildId);
const buttonType = ButtonStyle.Primary;
//setup embed
const embed = new EmbedBuilder()
.setTitle(perso.embed.title)
.setDescription(perso.embed.description)
.setColor(Colors.DarkVividPink)
.addFields(perso.embed.fields);
//setup buttons
const pButton = perso.button;
const LCButton = createButton(
...pButton.LC,
buttonType,
"822489141312618507",
);
const actuButton = createButton(
...pButton.actus,
buttonType,
"827160847017050132",
);
const components = [actuButton, LCButton];
const actionRow = new ActionRowBuilder().addComponents(components);
//get channel where to send
const guild = await interaction.guild.fetch();
const channel = await fetchChannel(
guild.channels,
currentServer.eventRoleHandleChannelId,
);
//send message
await channelSend(channel, {
embeds: [embed],
components: [actionRow],
});
interactionReply(interaction, perso.sent);
};
const allRoles = {
// Allows Ewibot to send all roles message
command: command,
action,
help: (interaction) => {
interactionReply(interaction, PERSONALITY.getPersonality().allRoles.help);
},
admin: true,
releaseDate: null,
sentinelle: false,
subcommands: ["all-roles"],
};
export default allRoles;