-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
112 lines (62 loc) · 2.17 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
require("dotenv").config();
const {Client} = require("discord.js");
const deploy = require("./deploy");
const client = new Client({
"intents": [
"GUILD_MESSAGES",
"GUILD_INTEGRATIONS",
"GUILD_WEBHOOKS",
"GUILDS"
]
});
// Deploy Commands
client.on("messageCreate", async (message) => {
if (!client.application?.owner) {
await client.application?.fetch();
}
if (client.application?.owner.id === message.author.id) {
if (message.content === "roles!deploy global") {
await deploy(client);
message.channel.send("Deployed Globaly!", {"messageReference": message.id});
} else if (message.guild && message.content === "roles!deploy") {
await deploy(client, message.guild.id);
message.channel.send("Deployed!", {"messageReference": message.id});
}
}
});
const commands = require("./commands");
const assignRole = require("./assignRole");
client.on("interactionCreate", (interaction) => {
if (!interaction.guild) {
interaction.reply("No can do! I am a guild only bot!").catch((error) => {
console.error("Interaction timed out:", error.stack, error);
});
}
if (interaction.isCommand()) {
commands[interaction.commandName].command(interaction);
} else if (interaction.isButton()) {
const [
commandName,
buttonName
] = interaction.customId.split("_");
if (commands[commandName]?.buttons[buttonName]) {
commands[commandName].buttons[buttonName](interaction);
} else {
assignRole(interaction);
}
} else {
console.log(interaction);
}
});
client.on("ready", () => {
console.log("bot connected");
});
const mongoose = require("mongoose");
mongoose.connect(process.env.DB_URL, {"useNewUrlParser": true,
"useUnifiedTopology": true});
const db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", () => {
console.log("db connected");
client.login(process.env.TOKEN);
});