-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
330 lines (254 loc) · 11 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
const { Client, Intents, MessageEmbed } = require('discord.js');
const keepAliveServer = require('./keep_alive.js');
const bot = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_MESSAGES]
});
const defaultPrefix = ';'; // Default prefix
// A map to store custom prefixes for each server
const serverPrefixes = new Map();
const startTime = Date.now(); // Store the bot's start time
// Simulate a simple economy system (for demonstration purposes)
const userBalances = new Map();
// Replace this function with the actual method to get the number of commands
function getNumberOfCommands() {
// Replace this with your logic to get the count of commands
return yourArrayOfCommands.length; // or yourCommandCountVariable
}
bot.on('guildMemberAdd', (member) => {
const channelId = '1196738471843340320'; // The Channel ID you just copied
const welcomeMessage = `Hey <@${member.id}>! Welcome to my server!`;
member.guild.channels.fetch(channelId).then(channel => {
channel.send(welcomeMessage);
});
// Initialize balance for the new member
userBalances.set(member.id, 1000);
});
bot.on('messageCreate', async (message) => {
if (message.author.bot) return;
bot.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
// Respond to mentions of the bot
if (interaction.mentions.has(bot.user)) {
const mentionEmbed = new MessageEmbed()
.setColor('#3498db')
.setTitle('Mention Information')
.setDescription(`Hey ${interaction.user.username}! Why did you ping me? Do ;ping & ;uptime to try me out!`);
interaction.reply({ embeds: [mentionEmbed] });
return;
}
// Parse the custom prefix or use the default prefix
const prefix = serverPrefixes.get(interaction.guild.id) || defaultPrefix;
// Check if the message starts with the bot's prefix
if (!interaction.content.startsWith(prefix)) return;
// Extract the command and arguments
const args = interaction.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
// ;ping command
if (command === 'ping') {
const apiLatency = Math.round(bot.ws.ping);
const botLatency = Date.now() - interaction.createdTimestamp;
const pingEmbed = new MessageEmbed()
.setColor('#3498db')
.setTitle('Ping Information')
.addField('API Latency', `${apiLatency}ms`, true)
.addField('Bot Latency', `${botLatency}ms`, true);
interaction.reply({ embeds: [pingEmbed] });
}
// ;uptime command
if (command === 'uptime') {
const uptime = Date.now() - startTime;
const formattedUptime = formatUptime(uptime);
const uptimeEmbed = new MessageEmbed()
.setColor('#3498db')
.setTitle('Uptime Information')
.addField('Bot Uptime', formattedUptime)
message.reply({ embeds: [uptimeEmbed] });
}
// ;botinfo command
if (command === 'botinfo') {
const { heapUsed, heapTotal } = process.memoryUsage();
const cpuUsage = process.cpuUsage();
const cpuUsagePercentage = ((cpuUsage.user + cpuUsage.system) / 1000000) * 100;
const botInfoEmbed = new MessageEmbed()
.setColor('#3498db')
.setTitle('Bot Information')
.addField('Ping', `${bot.ws.ping}ms`, true)
.addField('CPU', `${cpuUsagePercentage.toFixed(2)}%`, true)
.addField('Memory', `${(heapUsed / 1024 / 1024).toFixed(2)}MB / ${(heapTotal / 1024 / 1024).toFixed(2)}MB`, true)
.addField('Commands', getNumberOfCommands(14), true)
.addField('Guilds', bot.guilds.cache.size, true)
.addField('Users', bot.users.cache.size, true);
message.reply({ embeds: [botInfoEmbed] });
}
// ;userinfo command
if (command === 'userinfo') {
const targetMember = message.mentions.members.first() || message.member;
const targetUser = targetMember.user;
// Fetch the member to get the most up-to-date information
await targetMember.fetch();
const userInfoEmbed = new MessageEmbed()
.setColor('#2ecc71')
.setTitle('User Information')
.addField('User Tag', targetUser.tag, true)
.addField('User ID', targetUser.id, true)
.addField('Joined Server', targetMember.joinedAt.toISOString(), true)
.addField('Joined Discord', targetUser.createdAt.toISOString(), true);
message.reply({ embeds: [userInfoEmbed] });
return;
}
// ;serverinfo command
if (command === 'serverinfo') {
const server_info_embed = new MessageEmbed()
.setColor(0xe74c3c)
.setTitle('Server Information')
.addFields(
{ name: 'Server Name', value: message.guild.name, inline: true },
{ name: 'Server ID', value: message.guild.id, inline: true }
);
await message.reply({ embeds: [server_info_embed] });
}
// ;avatar command
if (command === 'avatar') {
const targetUser = message.mentions.users.first() || message.author;
const avatarEmbed = new MessageEmbed()
.setColor('#3498db')
.setTitle(`${targetUser.tag}'s Avatar`)
.setImage(targetUser.displayAvatarURL({ dynamic: true, size: 4096 }));
message.reply({ embeds: [avatarEmbed] });
}
// ;balance command
if (command === 'balance') {
// Check if a user is mentioned
const targetUser = message.mentions.users.first() || message.author;
const userId = targetUser.id;
// Check if the user exists in the balance map
if (!userBalances.has(userId)) {
return message.reply('Sorry, I couldn\'t fetch the balance at the moment.');
}
const userBalance = userBalances.get(userId);
const balanceEmbed = new MessageEmbed()
.setColor('#f39c12')
.setTitle(`${targetUser.tag}'s Wallet Balance`)
.setDescription(`The current balance is ${userBalance} coins.`);
message.reply({ embeds: [balanceEmbed] });
}
// ;work command
if (command === 'work') {
const earnings = Math.floor(Math.random() * 200) + 1; // Random earnings between 1 and 200 coins
// Update user balance
const userId = message.author.id;
const userBalance = (userBalances.get(userId) || 0) + earnings;
userBalances.set(userId, userBalance);
const workEmbed = new MessageEmbed()
.setColor('#27ae60')
.setTitle('Work Complete!')
.setDescription(`You earned ${earnings} coins for your hard work.`);
const balanceEmbed = new MessageEmbed()
.setColor('#3498db')
.setTitle('New Balance')
.setDescription(`Your new balance is ${userBalance} coins.`);
// Send separate embeds for clarity
await message.reply({ embeds: [workEmbed] });
await message.reply({ embeds: [balanceEmbed] });
}
// ;rob command
if (command === 'rob') {
const targetUser = message.mentions.users.first();
if (!targetUser) {
message.reply('Please mention a user to rob.');
return;
}
// Calculate a chance of success for the robbery
const successChance = Math.random();
if (successChance < 0.5) {
// Robbery failed
message.reply(`Oops! You tried to rob ${targetUser.tag} but failed. Better luck next time!`);
} else {
// Robbery successful
const stolenAmount = Math.floor(Math.random() * 200) + 1; // Random amount between 1 and 200 coins
// Update balances for both the robber and the target
const robberBalance = (userBalances.get(message.author.id) || 0) + stolenAmount;
const targetBalance = (userBalances.get(targetUser.id) || 0) - stolenAmount;
userBalances.set(message.author.id, robberBalance);
userBalances.set(targetUser.id, targetBalance);
const robEmbed = new MessageEmbed()
.setColor('#e74c3c')
.setTitle('Robbery Success!')
.setDescription(`You successfully robbed ${targetUser.tag} and stole ${stolenAmount} coins. Your new balance is ${robberBalance} coins.`);
message.reply({ embeds: [robEmbed] });
}
}
// ;prefix command
if (command === 'prefix') {
// Check if the user has permission to change the prefix (e.g., server admin)
if (!message.member.permissions.has('ADMINISTRATOR')) {
message.reply('You do not have permission to change the prefix.');
return;
}
const newPrefix = args[0];
// Check if a new prefix is provided
if (!newPrefix) {
message.reply(`The current prefix is \`${prefix}\`. To change it, use \`${prefix}prefix <new-prefix>\`.`);
return;
}
// Update the server's custom prefix
serverPrefixes.set(message.guild.id, newPrefix);
message.reply(`Prefix updated to \`${newPrefix}\`.`);
}
// ;banner command
if (command === 'banner') {
const targetUser = message.mentions.users.first() || message.author;
const bannerURL = targetUser.bannerURL({
size: 4096,
format: 'png',
dynamic: true,
});
if (bannerURL) {
const bannerEmbed = new MessageEmbed()
.setColor('#3498db')
.setTitle(`${targetUser.tag}'s Banner`)
.setImage(bannerURL);
await message.reply({ embeds: [bannerEmbed] }); // Added await here
} else {
await message.reply(`${targetUser.tag} does not have a banner.`); // Added await here
}
}
// ;servers command
if (command === 'servers') {
const serversEmbed = new MessageEmbed()
.setColor('#3498db')
.setTitle('Server Count')
.setDescription(`I am in ${bot.guilds.cache.size} servers.`);
await message.reply({ embeds: [serversEmbed] });
}
// Replace 'YOUR_CLIENT_ID' with your bot's client ID
const clientId = '1148609650334371852';
// ;invite
if (command === 'invite') {
const invite_link = `https://discord.com/oauth2/authorize?client_id=${bot.user.id}&scope=bot&permissions=8&scope=bot`;
const invite_embed = new MessageEmbed()
.setColor(0x3498db)
.setTitle('Invite the Bot')
.setDescription(`You can invite the bot to your server using the following link:\n[${invite_link}](${invite_link})`);
await message.reply({ embeds: [invite_embed] });
} else {
await bot.process_commands(message);
}
// ;setstatus
if (interaction.commandName.toLowerCase() === 'setstatus') {
// Assuming the desired status is 'Watching Hello World!'
setBotStatus('WATCHING', 'Hello World!');
await interaction.reply('Bot status updated!');
}
function setBotStatus(type = 'PLAYING', status = 'Hello World!') {
bot.user.setActivity(status, { type: type });
}
bot.login(token);
// Function to format uptime in a human-readable way
function formatUptime(uptime) {
const seconds = Math.floor(uptime / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
return `${days}d ${hours % 24}h ${minutes % 60}m ${seconds % 60}s`;
}