-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (53 loc) · 2.46 KB
/
index.js
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
const fs = require('fs')
const { Client, Intents, MessageActionRow, MessageSelectMenu, Permissions } = require('discord.js')
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] })
const config = require('./config.json')
const roleConfig = require('./roles.json')
client.once('ready', () => {
console.log('Ready!')
})
client.on("messageCreate", message => {
message.fetch()
if(!message.guild) return
if (!message.member) return;
if (!message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) return;
if (message.content == "!createSelectRoles") {
const rows = []
for (selecConNum in roleConfig) {
const selectConfig = roleConfig[selecConNum]
const OptionsArray = []
for (rolenum in selectConfig.options) {
const role = selectConfig.options[rolenum]
OptionsArray.push({ "label": message.guild.roles.cache.get(role.role).name, "value": message.guild.roles.cache.get(role.role).id })
if (role.emoji) OptionsArray[rolenum].emoji = role.emoji
if (role.description) OptionsArray[rolenum].description = role.description
}
const minValues = selectConfig.min ? selectConfig.min : 0
const maxValues = selectConfig.max ? selectConfig.max : selectConfig.options.length
const Row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.addOptions(OptionsArray)
.setCustomId(`${selecConNum}`)
.setMinValues(minValues)
.setMaxValues(maxValues)
.setPlaceholder(selectConfig.name)
)
rows.push(Row)
}
message.channel.send({
content: fs.readFileSync("./message.txt") + " ",
components: rows
})
}
})
client.on('interactionCreate', interaction => {
if (!interaction.isSelectMenu()) return
const reactionRoles = roleConfig[interaction.customId].options.map(x => x.role)
const currentRoles = interaction.member._roles
const selectedRoles = interaction.values
const remove = reactionRoles.filter(x => currentRoles.includes(x))
if (remove.length > 0) for (role of remove) { interaction.member.roles.remove(role) }
if (selectedRoles.length > 0) for (role of selectedRoles) { interaction.member.roles.add(role) }
interaction.deferUpdate()
})
client.login(config.token)