Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client, Collection } = require("discord.js");
- const Discord = require('discord.js')
- const AutoPoster = require('topgg-autoposter')
- const { addScalarDependencies, e } = require("mathjs");
- const config = require("./config");
- const mongoose = require('mongoose');
- const express = require('express')
- class EconomyClient extends Client {
- constructor() {
- super();
- this.discord = require("discord.js");
- this.fs = require("fs");
- this.path = require("path");
- this.mongoose = require("mongoose");
- this.commands = new Collection();
- this.timeouts = new Collection();
- this.ms = require('ms')
- this.config = {
- prefix: '$',
- };
- this.schema = this.mongoose.model(
- `economy`,
- new this.mongoose.Schema({
- User: String,
- Bobux: Number,
- })
- );
- const self = this
- this.economy = {
- async getBal(User) {
- return await self.schema.findOne({
- User
- }).then((d) => d ? d.Bobux : 0)
- },
- async addBal(User, Bobux) {
- return await self.schema.findOne({ User }, async(err, data) => {
- if(err) throw err
- if(data) {
- data.Bobux += Number(Bobux)
- } else {
- data = new self.schema({ User, Bobux })
- }
- data.save()
- })
- },
- async subBal(User, Bobux) {
- return await self.schema.findOne({ User }, async(err, data) => {
- if(err) throw err
- if(data) {
- data.Bobux -= Number(Bobux)
- } else {
- data = new self.schema({ User, Bobux })
- }
- data.save()
- })
- }
- }
- }
- commandHandler(path) {
- this.fs.readdirSync(this.path.normalize(path)).map((f) => {
- const File = require(this.path.join(__dirname, `.`, path, f));
- this.commands.set(File.name, File);
- });
- }
- getCommand(cmd) {
- return this.commands.has(cmd) ? this.commands.get(cmd) : false;
- }
- async start(token, path) {
- this.commandHandler(path);
- await this.mongoose.connect(
- `,
- {
- useNewUrlParser: true,
- useUnifiedTopology: true,
- useFindAndModify: false,
- }
- );
- this.on("ready", () => {
- const channel = this.channels.cache.get('844642765484720149');
- const embed = new this.discord.MessageEmbed()
- .setTitle('Bot restarting')
- .setTimestamp()
- channel.send(embed)
- setTimeout(() => {
- channel.send(`Restart successful`)
- }, 5000);
- this.user.setActivity(`$help || $donatehelp `).catch((err) => { throw err; })
- });
- this.on("message", async (message) => {
- if (
- message.author.bot ||
- !message.guild ||
- !message.content.toLocaleLowerCase().startsWith(this.config.prefix)
- ) return;
- const args =
- message.content.slice(this.config.prefix.length).trim().split(' ');
- const cmd = args.shift().toLocaleLowerCase();
- const command = this.getCommand(cmd) || this.commands.find(a => a.aliases && a.aliases.includes(cmd))
- if (!command) return;
- if (command.timeout) {
- if (this.timeouts.has(`${command.name}${message.author.id}`))
- return message.channel.send(
- this.embed({
- description: `You can't use this commmand for another ${this.ms(
- this.timeouts.get(`${command.name}${message.author.id}`) - Date.now(),
- { long: true }
- )}`,
- }, message)
- );
- command.run(this, message, args).catch(console.error);
- this.timeouts.set(
- `${command.name}${message.author.id}`,
- Date.now() + command.timeout
- );
- setTimeout(() => {
- this.timeouts.delete(`${command.name}${message.author.id}`);
- }, command.timeout);
- } else return command.run(this, message, args).catch(console.error);
- });
- this.on('guildCreate', async (guild, message) => {
- const Embed = new Discord.MessageEmbed()
- .setTitle('Boblox Help!')
- .addFields(
- { name: '💰 How to earn Bobux', value: '`$earnhelp`' },
- { name: '💸How to create and earn bobux off a game', value: '`$gamehelp`' },
- { name: '💹 Complete Guide on how to use boblox and become the richest', value: '`$guide`' },
- { name: '🧧 Donate to support us and recieve many Benefits', value: '`$donatehelp`' },
- { name: '💹 How to trade in the Boblox Stonk Market', value: '`$stonkhelp`' },
- )
- const owner = await guild.members.fetch(guild.ownerID);
- owner.send('Support/community server: https://discord.gg/BcNx4SUq54')
- owner.send(Embed)
- const yourembed = new this.discord.MessageEmbed()
- .setTitle('New server bois')
- .setDescription(`Server name: ${guild.name} \n Server id: ${guild.id} \n Server owner: ${owner} \n Member Count: ${guild.memberCount}`)
- const channel = this.channels.cache.get("836989035804753951")
- channel.send(yourembed)
- });
- await this.login(token);
- }
- embed(data, message) {
- return new this.discord.MessageEmbed({
- ...data,
- color: `RANDOM`,
- }).setTimestamp()
- }
- }
- module.exports = EconomyClient;
- new EconomyClient().start(require(`./config`).token, './commands', './index');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement