-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
134 lines (119 loc) · 3.47 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
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
const { Client, GatewayIntentBits,REST, Routes, Events } = require('discord.js');
require('dotenv').config();
const {CLIENT_ID,TOKEN,SUDO} = require("./config")
const fs = require("fs");
const client = new Client({ intents: [GatewayIntentBits.Guilds,GatewayIntentBits.GuildMembers] });
const rest = new REST({ version: '10' }).setToken(TOKEN);
const commands = {};
const buttons = {};
const readyList = []
const selectList = {}
const contextMenus = {}
const joinList = []
function Module(object,callback){
object.callback = callback
commands[object.name] = object
}
function onButton(object,callback){
object.callback = callback
buttons[object.name] = object
}
function onReady(object,callback){
object.callback = callback
readyList.push(object)
}
function onSelect(object,callback){
object.callback = callback
selectList[object.name] = object
}
function onCMenu(object,callback){
object.callback = callback
contextMenus[object.name] = object
}
function onJoin(object,callback){
object.callback = callback
joinList.push(object)
}
async function connect(){
const pluginFolder = "./plugins/";
const files = fs.readdirSync(pluginFolder);
files.forEach((file) => {
if (file.endsWith('.js')) {
const filePath = pluginFolder+file;
require(filePath);
}
});
try {
console.log('Started refreshing application (/) commands.');
await rest.put(Routes.applicationCommands(CLIENT_ID), { body: [...Object.values(commands),...Object.values(contextMenus)] });
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
client.on('ready',async () => {
console.log(`Logged in as ${client.user.tag}!`);
if(SUDO.length!=0){
let user = await client.users.fetch(SUDO[0])
user.send("Bot started..")
}
for(let i of readyList){
i.callback(client)
}
});
client.on('interactionCreate', async interaction => {
try{
if(interaction.isChatInputCommand()){
let command = commands[interaction.commandName]
if(command){
if(!command.owner || SUDO.includes(interaction.user.id)){
command.callback(interaction)
}
else{
await interaction.reply("This is an owner command")
}
}
}
else if(interaction.isButton()){
let id = interaction.customId.split("-")[0]
let button = buttons[id]
if(button){
button.callback(interaction)
}
}
else if(interaction.isAnySelectMenu()){
let id = interaction.customId.split("-")[0]
let select = selectList[id]
if(select){
select.callback(interaction)
}
}
else if(interaction.isUserContextMenuCommand()){
let command = contextMenus[interaction.commandName]
if(command){
command.callback(interaction)
}
}
else{
return ;
}
}
catch(e){
console.log(e);
}
});
client.on(Events.GuildMemberAdd, (member) => {
for(let i of joinList){
i.callback(member)
}
});
client.login(TOKEN);
}
module.exports = {
Module,
onButton,
onReady,
onSelect,
onCMenu,
onJoin
}
connect()