Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SuccessBot by Kinsler22
- const botconfig = require("./botconfig.json");
- const Discord = require("discord.js");
- const fs = require("fs");
- const mysql = require("mysql")
- const gf = require('../SuccessBot/globalFunctions.js');
- const schedule = require('node-schedule');
- const bot = new Discord.Client({disableEveryone: true});
- bot.commands = new Discord.Collection();
- fs.readdir("./commands/", (err, files) => {
- if (err) console.error(err);
- let jsfiles = files.filter(f => f.split(".").pop() === "js");
- if (jsfiles.length <= 0){
- console.log("No commands to load")
- return;
- }
- jsfiles.forEach((f,i) => {
- let props = require(`./commands/${f}`)
- bot.commands.set(props.help.name, props);
- });
- });
- const con = mysql.createConnection({
- host: 'Don't',
- user: 'Steal',
- password: 'My',
- database: 'Database',
- });
- con.connect((err) => {
- if(err){
- console.log('Error connecting to Db');
- console.log(err)
- return;
- }
- console.log('Connection established');
- });
- var checkForVerification = schedule.scheduleJob('*/1 * * * *', async message => {
- con.query(`SELECT * FROM statsTable WHERE verification != "_" && verification != "Verified" && discordUser = "_"`, (err,rows) => {
- if (err) throw err;
- if (rows < 1) return
- let count = 0
- while (count < rows.length){
- let guild = bot.channels.get(<THIS IS WHERE YOUR CHANNEL ID GOES>)
- console.log(rows[count].discordUser)
- let user = guild.members.get(`${rows[count].discordID}`)
- user.send(`Type !verify ${rows[count].verification} in chat if you want to link your Success stats from your twitch account ${rows[count].twitchUsername} with your Discord account. Note: this is permenant and codes expire at 2 AM EST every day`)
- count += 1
- }
- });
- });
- bot.on("ready", async () => {
- console.log(`${bot.user.username} is online!`);
- bot.user.setActivity("YOU 0.0", {type: "WATCHING"});
- });
- bot.on("guildMemberAdd", async member => {
- console.log("goes into function")
- let welcomechannel = member.guild.channels.find(`name`, "đź‘…welcome")
- welcomechannel.send(`${member} joined the discord. Have a great time :D`)
- });
- bot.on("guildMemberRemove", async member => {
- let welcomechannel = member.guild.channels.find(`name`, "đź‘…welcome")
- welcomechannel.send(`${member} has left the discord. They may or may not be missed :sob:`)
- });
- bot.on("message", async message => {
- if (message.author.bot) return;
- if (message.channel.type === "dm") return;
- let prefix = botconfig.index;
- if (!message.content.startsWith(prefix)){
- gf.messageXpGain(bot, message, con);
- return;
- }
- let messageArray = message.content.split(" ");
- let cmd = messageArray[0];
- let args = messageArray.slice(1);
- let command = bot.commands.get(cmd.slice(prefix.length))
- if (command) command.run(bot, message, args, con);
- if (cmd === `${prefix}hello`){
- return message.channel.send("Hello!");
- }
- });
- bot.login(botconfig.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement