Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as Discord from "discord.js";
- import { IBotCommand } from "./api";
- import * as ConfigFile from "./config";
- import * as db from "quick.db";
- const client: Discord.Client = new Discord.Client();
- //setting the econmy db up
- let economy = new db.table("economy")
- let commands:IBotCommand[] = [];
- loadCommands(`${__dirname}/commands`)
- client.on("ready", () => {
- console.log("Logged in!")
- let allUsers = client.users.array();
- //making sure everyone is in the db
- for(let i = 0; i< allUsers.length; i++){
- if(economy.get(allUsers[i].id) === null){
- economy.set(allUsers[i].id, {money:100})
- }
- }
- })
- client.on("guildMemberAdd", (member) => {
- //adding new people when they join
- if(economy.get(member.id) === null){
- economy.set(member.id, {money:100})
- }
- })
- client.on("message", msg => {
- if(msg.author.bot){return;}
- if(!msg.content.startsWith(ConfigFile.config.prefix)){return;}
- handleCommand(msg);
- // this is where im testng the db
- if(msg.content.startsWith("$money")){
- console.log(economy.get(`${msg.author.id}.money`))
- }
- })
- async function handleCommand(msg:Discord.Message) {
- let command = msg.content.split(' ')[0].replace(ConfigFile.config.prefix, "")
- let args = msg.content.split(" ").slice(1)
- for(const commandClass of commands){
- try{
- if(!commandClass.isThisCommand(command)){
- continue;
- }
- await commandClass.runCommand(args, msg, client)
- } catch(exepction){
- console.log(exepction)
- }
- }
- }
- function loadCommands(commandPath:string) {
- if(!ConfigFile.config || (ConfigFile.config.commands as string[]).length === 0){
- return;
- }
- for (const commandName of ConfigFile.config.commands as string[]){
- const commandClass = require(`${commandPath}/${commandName}`).default
- const command = new commandClass() as IBotCommand;
- commands.push(command);
- }
- }
- client.login(ConfigFile.config.token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement