more file reorganization, moved all events from index.js to events folder in seperate scripts
This commit is contained in:
parent
943c39a0bb
commit
1b03b8ca15
9 changed files with 29 additions and 134 deletions
103
src/index.js
103
src/index.js
|
@ -1,13 +1,7 @@
|
|||
require("dotenv").config();
|
||||
const {
|
||||
Client,
|
||||
Collection,
|
||||
GatewayIntentBits,
|
||||
Partials,
|
||||
} = require("discord.js");
|
||||
const { Client, GatewayIntentBits, Partials } = require("discord.js");
|
||||
|
||||
const log = require("./util/log.js").execute;
|
||||
const fs = require("fs");
|
||||
const events = require("./events/importEvents.js");
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
|
@ -20,103 +14,20 @@ const client = new Client({
|
|||
partials: [Partials.Message, Partials.Channel],
|
||||
});
|
||||
|
||||
client.commands = new Collection();
|
||||
|
||||
const commandFiles = fs
|
||||
.readdirSync("src/commands/")
|
||||
.filter((file) => file.endsWith(".js"));
|
||||
for (const file of commandFiles) {
|
||||
(async () => {
|
||||
const command = await import(`./commands/${file}`);
|
||||
client.commands.set(command.default.name, command.default);
|
||||
})();
|
||||
}
|
||||
|
||||
const prefix = process.env.PREFIX;
|
||||
|
||||
client.on("ready", (c) => {
|
||||
console.log(`${c.user.tag} is online.`);
|
||||
const channel = client.channels.cache.get("1148814162273763418");
|
||||
channel.send("pepperbot restart complete");
|
||||
client.on("ready", (rclient) => {
|
||||
events.ready(rclient);
|
||||
});
|
||||
|
||||
client.on("guildMemberAdd", (member) => {
|
||||
if (member.guild.id === "1112819622505365556") {
|
||||
fs.appendFileSync(
|
||||
"../pepperbot/src/data/guildmembers.log",
|
||||
member.user.username + ` -- added by bot: ${Date()} \n`
|
||||
);
|
||||
const channel = client.channels.cache.get("1148814162273763418");
|
||||
channel.send(
|
||||
`added new guild member ${member.user.username} (${member.user.id}) to members list`
|
||||
);
|
||||
}
|
||||
events.guildMemberAdd(member);
|
||||
});
|
||||
|
||||
client.on("messageDelete", async (message) => {
|
||||
if (message.content.startsWith(prefix)) {
|
||||
const args = message.content.slice(prefix.length).split(/ +/);
|
||||
const command = args.shift().toLowerCase();
|
||||
if (!client.commands.has(command)) {
|
||||
log(
|
||||
"deletedmessages.log",
|
||||
message,
|
||||
__filename,
|
||||
`deleted message from ${message.author.username} (${message.author}) with: "${message.content}"`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log(
|
||||
"deletedmessages.log",
|
||||
message,
|
||||
__filename,
|
||||
`deleted message from ${message.author.username} (${message.author}) with: "${message.content}"`
|
||||
);
|
||||
}
|
||||
events.messageDelete(message);
|
||||
});
|
||||
|
||||
client.on("messageCreate", async (message) => {
|
||||
if (message.channel.type === 1) {
|
||||
log(
|
||||
"directmessages.log",
|
||||
message,
|
||||
__filename,
|
||||
`direct message from ${message.author.username} (${message.author}) with: "${message.content}"`
|
||||
);
|
||||
}
|
||||
if (!message.content.startsWith(prefix)) return;
|
||||
const args = message.content.slice(prefix.length).split(/ +/);
|
||||
const command = args.shift().toLowerCase();
|
||||
|
||||
/*if (message.channelId !== "1148814162273763418") {
|
||||
let text = "commands only work in <#1148814162273763418>";
|
||||
if (!client.commands.has(command)) {
|
||||
text += ", also thats not a command lmao";
|
||||
}
|
||||
message.reply(text);
|
||||
return;
|
||||
}*/
|
||||
|
||||
if (!client.commands.has(command)) {
|
||||
message.reply("idiot thats not a command");
|
||||
log(
|
||||
"failed.log",
|
||||
message,
|
||||
__filename,
|
||||
`attempt to use invalid command: ${command} by: ${message.author.username} (${message.author})"`
|
||||
);
|
||||
}
|
||||
|
||||
if (client.commands.get(command)) {
|
||||
log(
|
||||
"commands.log",
|
||||
message,
|
||||
__filename,
|
||||
`use of command: ${command} by: ${message.author.username} (${message.author})"`,
|
||||
true
|
||||
);
|
||||
client.commands.get(command).execute(message, args, client);
|
||||
}
|
||||
events.messageCreate(message, client);
|
||||
});
|
||||
|
||||
client.login(process.env.TOKEN);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue