-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
210 lines (169 loc) · 8.16 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
const { Client, GatewayIntentBits, Presence, ActivityType, EmbedBuilder, userMention } = require("discord.js");
const { getImageUrlFull} = require("imagen-core");
const { getRandomAnimeImageUrl } = require('./modules/anime');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
]
});
const config = require("./config/config.json");
client.once("ready", () => {
console.log(`Sstudios bot © SstudiosDev - Connected as ${client.user.tag}`);
const formattedTime = config.showTimestamp ? new Date().toLocaleTimeString() : "";
const onlineMessageChannel = client.channels.cache.get(config.onlineMessageChannelId);
if (onlineMessageChannel) {
onlineMessageChannel.send(`${config.onlineMessage} ${formattedTime}`);
} else {
console.error(`Could not find the online message channel with ID: ${config.onlineMessageChannelId}`);
}
function updatePresence(){
const activities = [
{name:'Mostly sleepless🌛', type:ActivityType.Playing},
{name:'s!spigot', type:ActivityType.Watching},
];
const activity = activities[Math.floor(Math.random()* activities.length)];
client.user.setActivity(activity.name, {type:activity.type});
}
setInterval(updatePresence, 10000)
const channel = client.channels.cache.get("");
if (!channel) {
console.error("Could not find the channel.");
return;
}
setInterval(async () => {
try {
const animeImageUrl = await getRandomAnimeImageUrl();
const embed = new EmbedBuilder()
.setTitle("Random Anime Image")
.setColor(Math.floor(Math.random() * 16777215))
.setImage(animeImageUrl);
await channel.send({ embeds: [embed] });
} catch (error) {
console.error("Failed to send anime image:", error.message);
}
}, 600000);
});
client.on("guildMemberAdd", async (member) => {
// ID of the channel where the welcome message will be sent
const welcomeChannelId = ""; // Replace with the ID of your welcome channel
member.send(`Welcome to ${member.guild.name}! We hope you enjoy your stay on our server.`);
// Find the channel by its ID
const welcomeChannel = member.guild.channels.cache.get(welcomeChannelId);
// Check if the channel was found
if (welcomeChannel) {
// Send a welcome message
welcomeChannel.send(`Welcome to the server, ${member.user}! We hope you enjoy your stay.`);
// ID of the role to be assigned to the new member
const roleId = ""; // Replace with the ID of the role you want to assign
// Find the role by its ID
const role = member.guild.roles.cache.get(roleId);
// Check if the role was found
if (role) {
// Assign the role to the new member
await member.roles.add(role);
console.log(`Assigned the role ${role.name} to ${member.user.tag}`);
} else {
console.error(`Could not find the role with ID: ${roleId}`);
}
} else {
console.error(`Could not find the welcome channel with ID: ${welcomeChannelId}`);
}
});
client.on("messageCreate", async (message) => {
if (!message.content.startsWith(config.prefix) || message.author.bot) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === "spigot") {
// Crear un mensaje embed
const embed = new EmbedBuilder()
.setTitle("Spigot")
.setDescription(`Hello ${userMention(message.author.id)}, thank you for using this command. If you'd like to support us with our plugins, please visit this link and leave a positive review. Your feedback is invaluable to us! Thanks for your support! \n\n[SPIGOT LINK](https://www.spigotmc.org/members/sstudios-team.1957112/)\n`)
.setThumbnail('https://avatars.githubusercontent.com/u/4350249?s=200&v=4')
.setTimestamp()
.setFooter('Sstudios bot © SstudiosDev')
.setColor("#78dea6");
// Enviar el mensaje con el botón
message.channel.send({
embeds: [embed],
});
} else if (command === "clear") {
// Verificar si el autor del mensaje tiene permisos para borrar mensajes
if (!message.member.permissions.has("MANAGE_MESSAGES")) {
return message.reply("you don't have permission to use this command.");
}
// Verificar que se proporcionó un número de mensajes a borrar
const amount = parseInt(args[0]);
if (isNaN(amount) || amount < 1 || amount > 99) {
return message.reply("please provide a number between 1 and 99 to clear messages.");
}
// Borrar los mensajes
message.channel.bulkDelete(amount + 1)
.then(messages => {
message.channel.send(`Deleted ${messages.size} messages.`);
})
.catch(error => {
console.error("Error deleting messages:", error);
message.channel.send("An error occurred while deleting messages.");
});
} else if (command === "image") {
try {
const { imageUrlFull } = await getImageUrlFull();
const initialMessage = await message.channel.send('Obtaining a random image...');
setTimeout(async () => {
const embed = new EmbedBuilder()
.setTitle('Random Image')
.setDescription(`[Enlace](${imageUrlFull})`)
.setColor(Math.floor(Math.random() * 16777215))
.setImage(imageUrlFull);
await initialMessage.edit({ content: 'Here is your random image:', embeds: [embed] });
}, 3000);
} catch (error) {
console.error('Error when obtaining the random image:', error.message);
message.channel.send('Error when obtaining the random image.');
}
} else if (command === "anime") {
try {
const animeImageUrl = await getRandomAnimeImageUrl();
const initialMessage = await message.channel.send('Getting a random anime image...');
setTimeout(async () => {
const embed = new EmbedBuilder()
.setTitle('Random Anime Image')
.setDescription(`[Link](${animeImageUrl})`)
.setColor(Math.floor(Math.random() * 16777215))
.setImage(animeImageUrl);
await initialMessage.edit({ content: 'Here is your random anime image:', embeds: [embed] });
}, 3000);
} catch (error) {
console.error('Failed to get anime image:', error.message);
message.channel.send('Failed to get anime image.');
}
} else if (command === "servers") {
const guildsInfo = client.guilds.cache.map(guild => {
const owner = guild.owner ? guild.owner.user.tag : "Unknown";
const region = guild.region ? guild.region : "Unknown";
const createdAt = guild.createdAt ? guild.createdAt.toDateString() : "Unknown";
const channels = guild.channels.cache.map(channel => {
return `${channel.type === "GUILD_TEXT" ? "#" : ""}${channel.name}`;
}).join(", ");
const roles = guild.roles.cache.size;
const emojis = guild.emojis.cache.size;
return `**${guild.name}** (ID: ${guild.id})
• Members: ${guild.memberCount}
• Owner: ${owner}
• Region: ${region}
• Created at: ${createdAt}
• Channels: ${channels}
• Roles: ${roles}
• Emojis: ${emojis}`;
});
const embed = new EmbedBuilder()
.setTitle(`Server information (${client.guilds.cache.size})`)
.setDescription(guildsInfo.join("\n\n"))
.setColor(Math.floor(Math.random() * 16777215))
message.channel.send({ embeds: [embed] });
}
});
client.login(config.token);