committed event scripts (forgot to last time)
This commit is contained in:
parent
1b03b8ca15
commit
5b2bd43069
5 changed files with 99 additions and 0 deletions
62
src/events/messageCreate.js
Normal file
62
src/events/messageCreate.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
require("dotenv").config();
|
||||
const log = require("../util/log.js").execute;
|
||||
const fs = require("fs");
|
||||
const discord = require("discord.js");
|
||||
|
||||
commands = new discord.Collection();
|
||||
|
||||
const commandFiles = fs
|
||||
.readdirSync("src/commands/")
|
||||
.filter((file) => file.endsWith(".js"));
|
||||
for (const file of commandFiles) {
|
||||
(async () => {
|
||||
const command = await import(`../commands/${file}`);
|
||||
commands.set(command.default.name, command.default);
|
||||
})();
|
||||
}
|
||||
|
||||
const prefix = process.env.PREFIX;
|
||||
|
||||
module.exports.execute = function (message, client) {
|
||||
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 (!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 (commands.get(command)) {
|
||||
log(
|
||||
"commands.log",
|
||||
message,
|
||||
__filename,
|
||||
`use of command: ${command} by: ${message.author.username} (${message.author})"`,
|
||||
true
|
||||
);
|
||||
commands.get(command).execute(message, args, client);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue