Revolt-Bot/src/index.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-08-20 20:44:16 +02:00
import { Client, Message } from "revolt.js";
import { commandHandler } from "./utils/commandHandler"
import { nonCommandHandler } from "./utils/nonCommandHandler"
import { Database } from "bun:sqlite";
2023-08-20 20:44:16 +02:00
import config from "../config.json"
import dbInit from "utils/dbInit";
2023-08-20 20:44:16 +02:00
2024-03-15 18:41:08 +01:00
const client : Client = new Client({ eagerFetching: false });
const db = new Database(config.databaseName);
dbInit(db);
2023-08-20 20:44:16 +02:00
client.on("ready", async () => {
2024-03-15 18:41:08 +01:00
console.info(`logged in as ${client.user.username}!`)
client.user.edit(
{
status : {
text: config.prefix + " help for the help menu"
}
}
)
2023-08-20 20:44:16 +02:00
});
2024-03-15 18:41:08 +01:00
2023-08-20 20:44:16 +02:00
client.on("messageCreate", async (message: Message) => {
try{ if (!message.author) { await client.users.fetch(message.authorId) } }
2023-09-05 19:28:54 +02:00
catch(e){console.log(e)}
if (message.content === undefined) {return}
2024-03-15 18:41:08 +01:00
if (message.author?.bot) {return}
// checks if the message's body starts with the prefix
if (message.content.startsWith(config.prefix)) {
commandHandler(message, db, config.prefix);
}
2023-09-04 10:57:25 +02:00
else {
2024-03-15 18:41:08 +01:00
nonCommandHandler(message, db);
2023-09-05 19:40:46 +02:00
}
2023-08-20 20:44:16 +02:00
});
client.loginBot(config.botKey);