Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const discord = require("discord.js");
- const fs = require("fs");
- const config = require("./config.json");
- const token = require("./token.json").token;
- const bot = new discord.Client({
- disableEveryone: true
- });
- // When bot ready
- bot.on("ready", async () => {
- console.log(`${bot.user.username} is ready for action!`);
- if (config.activity.streaming == true) {
- bot.user.setActivity(config.activity.game, {
- url: 'https://twitch.tv/username'
- });
- } else {
- bot.user.setActivity(config.activity.game, {
- type: 'LISTENING'
- }); //PLAYING, LISTENING, WATCHING
- bot.user.setStatus('idle'); // dnd, idle, online, invisible
- }
- });
- client.on("guildCreate", guild => {
- guild.createChannel('rules','text')
- })
- // Load commands
- 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) return console.log("There are no commands to load...");
- console.log(`Loading ${jsfiles.length} commands...`);
- jsfiles.forEach((f, i) => {
- let props = require(`./commands/${f}`);
- console.log(`Command Number ${i + 1}, With the name ${f} has succesfully loaded loaded!`);
- bot.commands.set(props.help.name, props);
- });
- });
- // Message event
- bot.afk = new Map();
- bot.on("message", async message => {
- if (message.author.bot) return;
- if (message.channel.type === "dm") return;
- let prefix = config.prefix;
- let messageArray = message.content.split(" ");
- let command = messageArray[0].toLowerCase();
- let args = messageArray.slice(1);
- if (message.content.includes(message.mentions.users.first())) {
- bot.afk.forEach(key => {
- if (key.id == message.mentions.users.first().id) {
- message.guild.fetchMember(key.id).then(member => {
- let user_tag = member.user.tag;
- return message.channel.send(`**${user_tag}** is currently afk. Reason: ${key.reason}`);
- });
- }
- });
- }
- bot.afk.forEach(key => {
- if (message.author.id == key.id) {
- bot.afk.delete(message.author.id);
- return message.reply(`You have been removed from the afk list!`).then(msg => msg.delete(5000));
- }
- });
- if (!command.startsWith(prefix)) return;
- let cmd = bot.commands.get(command.slice(prefix.length));
- if (cmd) cmd.run(bot, message, args);
- });
- bot.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement