-
Notifications
You must be signed in to change notification settings - Fork 0
/
trsltindex.js
133 lines (121 loc) · 4.07 KB
/
trsltindex.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
const fs = require("node:fs");
const path = require("node:path");
//testpushERERRRR
const {
ActivityType,
Client,
Collection,
GatewayIntentBits,
Events,
EmbedBuilder,
WebhookClient,
AttachmentBuilder,
} = require("discord.js");
const deploycommands = require("./deploy-commands.js");
require("dotenv").config();
const webhook = process.env.TRANSLATEHOOK;
const info = webhook.split("/api/webhooks/");
const hookarr = info[1].split("/");
const webhookToken = hookarr[hookarr.length - 1];
const webhookId = hookarr[hookarr.length - 2];
const webhookClient = new WebhookClient({ id: webhookId, token: webhookToken });
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers],
});
client.commands = new Collection();
const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
}
deploycommands();
client.on("interactionCreate", async (interaction) => {
if (interaction.isChatInputCommand()) {
const command = client.commands.get(interaction.commandName);
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
}
} else if (interaction.isContextMenuCommand()) {
const contextcommand = client.commands.get(interaction.commandName);
try {
await contextcommand.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
}
} else return;
});
client.login(process.env.BOTTOKEN);
client.once("ready", () => {
console.log("Ready!");
client.user.setAvatar("./imgs/avatar.png");
setInterval(function () {
let servercount = client.guilds.cache.size;
client.user.setActivity(`${servercount} Servers`, {
type: ActivityType.Watching,
});
}, 20000);
});
client.on("guildCreate", async (guild) => {
const guildid = guild.id;
const guildname = guild.name;
const guildicon = guild.iconURL();
const serverowner = guild.ownerId;
const ownerobj = await client.users.fetch(serverowner);
const ownerusername = `${ownerobj.username}#${ownerobj.discriminator}`;
let membercount = 0;
const serverscache = client.guilds.cache;
serverscache.forEach((element) => {
const memberamount = element.memberCount;
membercount = membercount + memberamount;
});
const embedadded = new EmbedBuilder()
.setTitle("Added to a Server")
.setColor("#33FFAF")
.setImage(guildicon)
.setDescription(
`I was added to a server!!\n\nServer - \`${guildname}\` [\`${guildid}\`]\nOwner - <@${serverowner}> [\`${ownerusername} - ${serverowner}\`]\n\nNew Total - Membercount - ${membercount}`
);
webhookClient.send({
content: "<@632252672338165801>",
embeds: [embedadded],
});
});
client.on("guildDelete", async (guild) => {
const guildid = guild.id;
const guildname = guild.name;
const guildicon = guild.iconURL();
const serverowner = guild.ownerId;
const ownerobj = await client.users.fetch(serverowner);
const ownerusername = `${ownerobj.username}#${ownerobj.discriminator}`;
let membercount = 0;
const serverscache = client.guilds.cache;
serverscache.forEach((element) => {
const memberamount = element.memberCount;
membercount = membercount + memberamount;
});
const embedremoved = new EmbedBuilder()
.setTitle("Removed from Server")
.setColor("ff0000")
.setImage(guildicon)
.setDescription(
`I left a server!!\n\nServer - \`${guildname}\` [\`${guildid}\`]\nOwner - <@${serverowner}> [\`${ownerusername} - ${serverowner}\`]\n\nNew Total - Membercount - ${membercount}`
);
webhookClient.send({
content: "<@632252672338165801>",
embeds: [embedremoved],
});
});