269 lines
9.3 KiB
JavaScript
269 lines
9.3 KiB
JavaScript
const fs = require('fs');
|
|
const Discord = require("discord.js");
|
|
const config = require("./configs/config.json");
|
|
const { registerCommands } = require("./helper/commandRegistration.js");
|
|
|
|
let reactionConfig;
|
|
|
|
const client = new Discord.Client(
|
|
{
|
|
partials: [
|
|
Discord.Partials.Channel,
|
|
Discord.Partials.Reaction,
|
|
Discord.Partials.Message,
|
|
Discord.Partials.User
|
|
],
|
|
intents: [
|
|
Discord.IntentsBitField.Flags.MessageContent,
|
|
Discord.IntentsBitField.Flags.Guilds,
|
|
Discord.IntentsBitField.Flags.GuildMembers,
|
|
Discord.IntentsBitField.Flags.GuildMessages,
|
|
Discord.IntentsBitField.Flags.GuildMessageTyping,
|
|
Discord.IntentsBitField.Flags.GuildMessageReactions,
|
|
Discord.IntentsBitField.Flags.GuildVoiceStates,
|
|
Discord.IntentsBitField.Flags.DirectMessages,
|
|
Discord.IntentsBitField.Flags.DirectMessageReactions,
|
|
]
|
|
}
|
|
);
|
|
|
|
client.commands = new Discord.Collection();
|
|
|
|
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
|
|
for(const file of commandFiles){
|
|
const command = require (`./commands/${file}`);
|
|
|
|
client.commands.set(command.name, command);
|
|
}
|
|
|
|
registerCommands();
|
|
|
|
|
|
async function deleteAllMessages(channelId) {
|
|
const channel = await client.channels.fetch(channelId);
|
|
|
|
if (!channel.isTextBased()) {
|
|
console.error('The provided channel is not a text channel.');
|
|
return;
|
|
}
|
|
|
|
let fetchedMessages;
|
|
do {
|
|
// Fetch up to 100 messages at a time
|
|
fetchedMessages = await channel.messages.fetch({ limit: 100 });
|
|
|
|
// Filter messages older than 14 days
|
|
const recentMessages = fetchedMessages.filter(msg => Date.now() - msg.createdTimestamp < 14 * 24 * 60 * 60 * 1000);
|
|
|
|
// Bulk delete recent messages
|
|
if (recentMessages.size > 0) {
|
|
await channel.bulkDelete(recentMessages, true).catch(console.error);
|
|
}
|
|
|
|
// Delete older messages one by one
|
|
for (const [id, msg] of fetchedMessages) {
|
|
if (Date.now() - msg.createdTimestamp >= 14 * 24 * 60 * 60 * 1000) {
|
|
await msg.delete().catch(console.error);
|
|
}
|
|
}
|
|
} while (fetchedMessages.size > 0);
|
|
}
|
|
|
|
|
|
/* Actual Bot */
|
|
|
|
client.once(Discord.Events.ClientReady, () => {
|
|
console.log(`Bot is online!`);
|
|
});
|
|
|
|
client.on(Discord.Events.InteractionCreate, async (interaction) => {
|
|
if (!interaction.isCommand()) return;
|
|
const {commandName} = interaction;
|
|
const command = client.commands.get(commandName);
|
|
|
|
try {
|
|
await command.execute(interaction, Discord, client);
|
|
} catch (error) {
|
|
console.error(error);
|
|
interaction.reply({content: "There was an error while executing this command!", flags: Discord.MessageFlags.Ephemeral});
|
|
}
|
|
});
|
|
|
|
client.on(Discord.Events.MessageReactionAdd, async (reaction, user, detail) => {
|
|
try {
|
|
const data = fs.readFileSync("./configs/reactionRole.json", "utf8");
|
|
reactionConfig = JSON.parse(data);
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
try {
|
|
const emoji = reaction._emoji;
|
|
const emojiId = (emoji.id == null) ? emoji.name : emoji.id;
|
|
const member = reaction.message.guild.members.cache.get(user.id);
|
|
const messageID = reaction.message.id;
|
|
|
|
const ReactionRoleMessage = reactionConfig.find(entry => entry.messageid === messageID);
|
|
|
|
const ReactionRole = ReactionRoleMessage.reactions.find(entry => entry.id === emojiId);
|
|
|
|
member.roles.add(ReactionRole.role);
|
|
} catch (error) {
|
|
|
|
const messageID = reaction.message.id;
|
|
|
|
const ReactionRoleMessage = reactionConfig.find(entry => entry.messageid === messageID);
|
|
|
|
if (ReactionRoleMessage !== undefined) {
|
|
reaction.remove();
|
|
}
|
|
|
|
return;
|
|
}
|
|
});
|
|
|
|
client.on(Discord.Events.MessageReactionRemove, async (reaction, user, detail) => {
|
|
try {
|
|
const data = fs.readFileSync("./configs/reactionRole.json", "utf8");
|
|
reactionConfig = JSON.parse(data);
|
|
} catch (err) {
|
|
|
|
}
|
|
|
|
try {
|
|
const emoji = reaction._emoji;
|
|
const emojiId = (emoji.id == null) ? emoji.name : emoji.id;
|
|
const member = reaction.message.guild.members.cache.get(user.id);
|
|
const messageID = reaction.message.id;
|
|
|
|
const ReactionRoleMessage = reactionConfig.find(entry => entry.messageid === messageID);
|
|
|
|
const ReactionRole = ReactionRoleMessage.reactions.find(entry => entry.id === emojiId);
|
|
|
|
member.roles.remove(ReactionRole.role);
|
|
} catch (error) {
|
|
//console.log(error);
|
|
return;
|
|
}
|
|
});
|
|
|
|
client.on(Discord.Events.GuildMemberAdd, (member) => {
|
|
const channel = member.guild.channels.cache.get("1365280174811385866");
|
|
channel.send(`🎉🎉 Welcome to the ◄Furry Chill Space►, ${member}! Everyone say Hi to them! 🎉🎉`);
|
|
})
|
|
|
|
client.on(Discord.Events.MessageCreate, async (message) => {
|
|
if (message.author.bot) {
|
|
return;
|
|
}
|
|
|
|
//console.log(message);
|
|
|
|
if (message.content === "pur" && message.author.id === "277357956075356162" && message.channel.id === "1364894453147500604") {
|
|
|
|
const channelId = message.channel.id;
|
|
await deleteAllMessages(channelId);
|
|
|
|
const rules = new Discord.EmbedBuilder()
|
|
.setColor(0x0ce813)
|
|
.setTitle('The Rules of the Server')
|
|
.setThumbnail('https://cdn.discordapp.com/icons/1364894253024546816/04a5ed623bb8bed8777023265323092b.webp')
|
|
.addFields(
|
|
{name: '🔴 Don\'t be rude', value: 'Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.'},
|
|
{name: '🔴 No Advertisement', value: 'No spam or self-promotion (server invites, advertisements, etc) without permission from a staff member. This includes DMing fellow members.'},
|
|
{name: '🔴 Feel free to report on rule breaking actions', value: 'If you see something against the rules or something that makes you feel unsafe, let staff know. We want this server to be a welcoming space!'},
|
|
{name: '🔴 No NSFW-Stuff', value: 'No age-restricted or obscene content. This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content. Except there is a Channel for that.'},
|
|
)
|
|
.setFooter({ text: 'Furry forever'});
|
|
|
|
message.channel.send({ embeds: [rules] });
|
|
}
|
|
|
|
|
|
if (message.content === "pur" && message.author.id === "277357956075356162" && message.channel.id === "1365280781840289853") {
|
|
const colors = new Discord.EmbedBuilder()
|
|
.setColor(0x03fcb6)
|
|
.setTitle('Choose your custom Color')
|
|
.addFields(
|
|
{name: '🔴 Red', value: ''},
|
|
{name: '🟠 Orange', value: ''},
|
|
{name: '🟡 Yellow', value: ''},
|
|
{name: '🟢 Green', value: ''},
|
|
{name: '🔵 Blue', value: ''},
|
|
{name: '🟣 Purple', value: ''},
|
|
{name: '🟤 Brown', value: ''},
|
|
{name: '⚫ Black', value: ''},
|
|
{name: '⚪ White', value: ''},
|
|
)
|
|
.setFooter({ text: 'After Clicking the Reactions on the Message,\nyou will have them applied on your Profile'});
|
|
|
|
//message.channel.send({ embeds: [rules] });
|
|
|
|
const channel1 = message.channel;
|
|
const messageId1 = '1366567818572599317';
|
|
|
|
try {
|
|
const msgToEdit = await channel1.messages.fetch(messageId1);
|
|
await msgToEdit.edit({ embeds: [colors] });
|
|
} catch (error) {
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const gender = new Discord.EmbedBuilder()
|
|
.setColor(0x03fcb6)
|
|
.setTitle('Select your Gender')
|
|
.addFields(
|
|
{name: '♂️ Male', value: ''},
|
|
{name: '♀️ Female', value: ''},
|
|
{name: ':regional_indicator_n: Non-Binary', value: ''},
|
|
{name: '🏳️⚧️ Trans', value: ''},
|
|
{name: ':regional_indicator_o: Other', value: ''},
|
|
)
|
|
.setFooter({ text: 'After Clicking the Reactions on the Message,\nyou will have them applied on your Profile'});
|
|
|
|
const channel2 = message.channel;
|
|
const messageId2 = '1366723312075673641';
|
|
|
|
try {
|
|
const msgToEdit = await channel2.messages.fetch(messageId2);
|
|
await msgToEdit.edit({ embeds: [gender] });
|
|
} catch (error) {
|
|
return;
|
|
}
|
|
|
|
|
|
message.delete();
|
|
}
|
|
|
|
if (message.author.id !== "277357956075356162" && message.channel.id === "1365280781840289853" && !message.author.bot) {
|
|
message.delete();
|
|
}
|
|
})
|
|
|
|
client.on(Discord.Events.VoiceStateUpdate, async (oldstate, newstate) => {
|
|
const currentUser = await client.guilds.cache.get(config.guildId).members.cache.get((typeof oldstate != "undefined") ? oldstate.id : newstate.id).user;
|
|
const currentChannel = await client.guilds.cache.get(config.guildId).channels.cache.get((typeof oldstate != "undefined" || typeof oldstate != "null") ? oldstate.channelId : newstate.channelId);
|
|
|
|
console.log(currentChannel);
|
|
|
|
|
|
|
|
if (typeof newstate != "undefined") {
|
|
// Join
|
|
|
|
|
|
|
|
}
|
|
if (typeof oldstate != "undefined") {
|
|
// Leave
|
|
|
|
|
|
|
|
}
|
|
});
|
|
|
|
client.login(`${config.token}`); |