Personal Project

For my senior personal project I decided I wanted to make a Discord Bot that helps me run my Discord Server. I like to have a theme in my server based on upcoming holidays, and before making the bot, I would go through each text and voice channel and change the emojis by hand. Seeing as I planned to run this server for a long time, and I really liked having the themed emojis, I decided to explore making a Discord Bot with JavaScript, using the Discord.JS library. Making the bot served two purposes, the first was simply to make changing the emojis much faster, the second was to learn how to make a bot with zero experience and see if I could do it. Needless to say, I got the bot working, and I have become a lot more familiar with JavaScript.

Code Snippet

                     
                         const BaseCommand = require('../../utils/structures/BaseCommand');

                         module.exports = class TextCommand extends BaseCommand {
                         constructor() {
                         super('text', 'test', []);
                         }

                         async run(client, message, args) {
                         //command: text 😍
                         //discord server id: 3812335977********

                         //variables
                         const emoji = args.slice(0).join(" ");
                         //const channelList = [];
                         var array = [];

                         //input check
                         if (!emoji) return message.channel.send("You must include an emoji");

                         //execute
                         getChannelIDs();
                         for (let i = 0; i < array.length; i++) {
                         var channelid = array[i].toString();
                         var channelType = message.guild.channels.cache.get(channelid).type;
                         //console.log(channelType);
                         if (channelType == 'text') {
                         let channelName = message.guild.channels.cache.get(channelid).name;
                         //console.log(channelName);
                         let nameToArray = [...channelName];
                         nameToArray.shift();
                         nameToArray.unshift(emoji);
                         nameToArray.pop();
                         nameToArray.push(emoji);
                         const newName = nameToArray.join('');
                         message.guild.channels.cache.get(channelid).setName(newName);
                         }
                         }

                         //functions
                         function getChannelIDs(fetch) {
                         try {
                         let channels = client.channels.cache.array();
                         for (const channel of channels) {
                         array.push(channel.id);
                         //console.log(channel.id);
                         }
                         } catch (err) {
                         console.log('array error')
                         message.channel.send('An error occoured while getting the channels.')
                         console.log(err)
                         }

                         return array;
                         }
                         }
                         }