-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #861 from Glazelf/modular
Modular Ninigi
- Loading branch information
Showing
158 changed files
with
2,289 additions
and
2,104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,65 @@ | ||
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]; | ||
import Discord from "discord.js"; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import config from './config.json' with { type: "json" }; | ||
|
||
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}`)]; | ||
}); | ||
// All except guild presence | ||
// privileged: MessageContent, GuildMembers, GuildPresence | ||
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" | ||
}); | ||
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(async (file) => { | ||
// If the file is not a JS file, ignore it. | ||
if (!file.endsWith(".js")) return; | ||
// Load the event file itself | ||
let event = await import(`./events/${file}`); | ||
event = event.default; | ||
// 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)); | ||
}); | ||
client.commands = new Discord.Collection(); | ||
client.aliases = new Discord.Collection(); | ||
await walk(`./commands/`); | ||
console.log("Loaded commands!"); | ||
}); | ||
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); | ||
}); | ||
}; | ||
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, async function (err, stats) { | ||
if (stats.isDirectory()) { | ||
walk(filepath, callback); | ||
} else if (stats.isFile() && file.endsWith('.js')) { | ||
let props = await import(`./${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); | ||
}); | ||
}; | ||
}); | ||
}; | ||
}); | ||
}); | ||
}; | ||
}; | ||
botjsFunction(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.