PepperBot/src/index.js
2023-09-09 14:20:07 -07:00

128 lines
3.3 KiB
JavaScript

require("dotenv").config();
const {
Client,
IntentsBitField,
EmbedBuilder,
Collection,
} = require("discord.js");
const fs = require("fs");
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});
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("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)) {
fs.appendFileSync(
"../pepperbot/src/logs/deletedmessages.log",
"deleted message from: " +
message.author.username +
"(" +
message.author +
") at " +
Date() +
' with: "' +
message.content +
'"\n'
);
}
} else {
fs.appendFileSync(
"../pepperbot/src/logs/deletedmessages.log",
"deleted message from: " +
message.author.username +
"(" +
message.author +
") at " +
Date() +
' with: "' +
message.content +
'"\n'
);
}
});
client.on("messageCreate", async (message) => {
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");
fs.appendFileSync(
"../pepperbot/src/logs/failed.log",
"invalid command: " + "from: " + message.content + " at " + Date() + "\n"
);
}
if (client.commands.get(command)) {
client.commands.get(command).execute(message, args, client);
}
});
client.on("interactionCreate", (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === "test") {
interaction.reply(
"mothafucka you contacted my ass from a slash command end urself"
);
}
if (interaction.commandName === "say") {
try {
const msg = interaction.options.get("message");
interaction.reply(msg.value);
} catch (error) {
console.log(error);
fs.appendFile(
"../pepperbot/src/logs/errors.log",
error + "from: " + interaction.msg + " at " + Date()
);
}
}
if (interaction.commandName === "commands") {
client.commands.get("commands").execute(interaction, undefined);
}
});
client.login(process.env.TOKEN);