75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
const { Client, Events, GatewayIntentBits, Collection } = require("discord.js");
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
let cfg = {};
|
|
try {
|
|
cfg = require("./config.json");
|
|
} catch (e) {
|
|
console.warn(
|
|
"config.json not found or invalid. Falling back to environment variables."
|
|
);
|
|
}
|
|
const token = process.env.TOKEN || cfg.TOKEN;
|
|
const prefix = process.env.PREFIX || cfg.PREFIX;
|
|
const client = new Client({
|
|
intents: [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.MessageContent,
|
|
],
|
|
});
|
|
client.commands = new Collection();
|
|
|
|
fs.readdir("./commands/", (err, files) => {
|
|
if (err) return console.error(err);
|
|
files.forEach((file) => {
|
|
if (!file.endsWith(".js")) return;
|
|
let props = require(`./commands/${file}`);
|
|
let commandName = file.split(".")[0];
|
|
console.log("Loaded command " + commandName);
|
|
client.commands.set(commandName, props);
|
|
});
|
|
});
|
|
|
|
const url = "https://drive.overflow.fun/public/react.json";
|
|
let userstoreact = [];
|
|
client.once(Events.ClientReady, async (readyClient) => {
|
|
const res = await fetch(url);
|
|
const data = await res.json();
|
|
|
|
userstoreact = data.map((entry) => {
|
|
const [userId, emoji] = entry.split(":");
|
|
return { userId, emoji };
|
|
});
|
|
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
|
|
});
|
|
|
|
client.on(Events.MessageCreate, async (message) => {
|
|
if (message.author.bot) return;
|
|
console.log(message.mentions.users);
|
|
|
|
userstoreact.forEach(async (usr) => {
|
|
if (message.mentions.users.find((u) => u.id == usr.userId)) {
|
|
try {
|
|
await message.react(usr.emoji);
|
|
} catch (err) {
|
|
console.error("Failed to react to message:", err);
|
|
}
|
|
}
|
|
});
|
|
|
|
if (message.content.indexOf(prefix) !== 0) return;
|
|
|
|
const args = message.content.slice(prefix.length).trim().split(/ +/g);
|
|
const command = args.shift().toLowerCase();
|
|
|
|
const cmd = client.commands.get(command);
|
|
|
|
if (!cmd) return;
|
|
|
|
cmd.run(client, message, args);
|
|
});
|
|
|
|
// Log in to Discord with your client's token
|
|
client.login(token);
|