-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
76 lines (53 loc) · 2.7 KB
/
app.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
63
64
65
66
67
68
69
70
71
72
73
74
75
import {Client} from "discord.js"
import fs, { readdirSync } from "fs"
import "dotenv/config"
const client = new Client({intents:["GuildMembers","GuildMessages","GuildIntegrations","Guilds","MessageContent"]})
const event = await import(`./event/ready.js`).then(m=>m.default)
event(client)
client.on("interactionCreate", async interaction =>{
if (interaction.commandName == "create_role") { //create_role command name
if (!fs.existsSync(`./guilds_info/${interaction.guildId}.txt`)) { //checking if role_admin roles not exists
return interaction.reply("Please adjust the approved or rejected role votes by **/role_admin**")
}
if (interaction.guild.roles.cache.map(role => role.name.toLowerCase()).includes(interaction.options.get('rol_name').value.toLowerCase())){ //checking if rol name already in use
return interaction.reply({ content: '**Role name is already in use**', ephemeral: true }) }
const role_create_func = await import("./commands/role_create.js").then(m=> m.default)
role_create_func(interaction) //then running role create function
}
if (interaction.commandName == "role_admin") {
const role_admin_func = await import("./commands/role_admin.js").then(m=>m.default)
role_admin_func(interaction)
}
if (interaction.commandName == "get_role") { //checking if get_role command
const get_role_func = await import("./commands/get_role.js").then(m=>m.default)
get_role_func(interaction)
}
if (interaction.commandName == "show_role") { //checking if mention_role command
let role_id = interaction.options.get('role').value
const guild = client.guilds.cache.get(interaction.guildId)
await guild.fetch()
await guild.members.fetch() //updating discord users data and roles data
let user_ids = guild.roles.cache.get(role_id).members.map(m => m.user.username)
if (user_ids.length <= 0) {
interaction.reply("**No user has this role !**")
}
else {
let msg_content = ""
user_ids.forEach(element =>{
msg_content += `@${element}, `
})
interaction.reply({ content: msg_content, ephemeral: true })
}
/*
This command will help you about your server users. For example:
If users join server, then It can be showed who has the role that user select.
*/
}
//help command about how to use bot
if (interaction.commandName == "help") { //help command about how to use bot
const help_message = await import("./guilds_info/help.js").then(m=>m.default)
await interaction.reply(help_message) // help message content is in guilds/info/help.js
// help message content is in guilds/info/help.js
}
})
client.login(process.env.token) //bot token