forked from Glazelf/NinigiBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
68 lines (66 loc) · 3.49 KB
/
bot.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
let botjsFunction = async function botjsFunction() {
const Discord = require('discord.js');
const fs = require("fs");
const path = require("path");
// all except guild presence
// privileged: MessageContent, GuildMembers
const intents = [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMembers, Discord.GatewayIntentBits.GuildBans, Discord.GatewayIntentBits.GuildEmojisAndStickers, Discord.GatewayIntentBits.GuildIntegrations, Discord.GatewayIntentBits.GuildVoiceStates, Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.GuildMessageReactions, Discord.GatewayIntentBits.DirectMessages, Discord.GatewayIntentBits.MessageContent];
const partials = [Discord.Partials.Channel, Discord.Partials.GuildMember, Discord.Partials.Message, Discord.Partials.Reaction, Discord.Partials.User];
const client = new Discord.Client({
intents: intents,
partials: partials,
allowedMentions: { parse: ['users', 'roles'], repliedUser: true },
shards: "auto"
});
const config = require("./config.json");
client.config = config;
// This loop reads the /events/ folder and attaches each event file to the appropriate event.
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
// If the file is not a JS file, ignore it.
if (!file.endsWith(".js")) return;
// Load the event file itself
const event = require(`./events/${file}`);
// Get just the event name from the file name
let eventName = file.split(".")[0];
// Each event will be called with the client argument,
// followed by its "normal" arguments, like message, member, etc.
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
await walk(`./commands/`);
console.log("Loaded commands!");
client.login(config.token);
// This loop reads the /commands/ folder and attaches each command file to the appropriate command.
async function walk(dir, callback) {
fs.readdir(dir, function (err, files) {
if (err) throw err;
files.forEach(function (file) {
let filepath = path.join(dir, file);
fs.stat(filepath, function (err, stats) {
if (stats.isDirectory()) {
walk(filepath, callback);
} else if (stats.isFile() && file.endsWith('.js')) {
let props = require(`./${filepath}`);
if (!props.config.type) props.config.type = Discord.ApplicationCommandType.ChatInput;
let commandName = file.split(".")[0];
// console.log(`Loaded command: ${commandName} ✔`);
client.commands.set(commandName, props);
if (props.config.aliases) {
props.config.aliases.forEach(alias => {
if (client.aliases.get(alias)) return console.log(`Warning: Two commands share an alias name: ${alias}`);
client.aliases.set(alias, commandName);
});
};
};
});
});
});
};
};
let botjs = botjsFunction;
botjsFunction();