Last active
April 4, 2025 00:03
-
-
Save ember-ana/b5c8542bc951fed0be9e4b3849c5d8da to your computer and use it in GitHub Desktop.
for anyone stumbling upon this from my profile: this was a code review for someone's first Discord bot as a complete beginner to JavaScript :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Discord = require("discord.js"); | |
const TOKEN = "TOKEN"; | |
const { Client, RichEmbed } = require('discord.js'); | |
// Why do you require discord.js twice? the require call in line 1 is redundant | |
var bot = new Discord.Client(); | |
// since you required Client explicitely, you could do new Client() instead of new Discord.Client(); | |
// var is kinda deprecated, I suggest you use const, as the bot variable doesn't change in the future | |
// bot is not really what this represents; the bot is so much more than just the discord client instance, hence the name client would be more fitting for the variable | |
bot.on("ready", function() { // try to stick to a consistent quote style - either always doubles, or always singles | |
console.log('ready'); | |
}); | |
bot.on("message", function(message) { | |
if (message.content === "activateBot") { | |
const embed = new RichEmbed() | |
.setTitle('Music Bot Control Panel') | |
.setColor(0x00FF00) // latest discord.js also supports '00FF00' if I'm not mistaken, instead of the hex literal | |
.setDescription('Control the Bot using the Reaktions!'); | |
message.channel.send(embed); | |
} | |
if (message.embeds[0] && message.author.equals(bot.user)) { // you could do this directly after sending the message, instead of waiting for the next message event | |
message.react("⏮") | |
.then(() => message.react("▶")) | |
.then(() => message.react("⏸")) | |
.then(() => message.react("⏭")); | |
} | |
}); | |
bot.on('messageReactionAdd', (reaction, user) => { | |
if (!user.bot) { // maybe this could be if (user.bot) return; to not have everything inside an if clause | |
if (reaction.emoji.name === "⏮") { // here, possible switch/case could be used for cleaner code | |
reaction.message.channel.send('!back'); | |
} | |
if (reaction.emoji.name === "▶") { | |
reaction.message.channel.send('!play'); | |
} | |
if (reaction.emoji.name === "⏸") { | |
reaction.message.channel.send('!pause'); | |
} | |
if (reaction.emoji.name === "⏭") { | |
reaction.message.channel.send('!next'); | |
} | |
reaction.remove(user); | |
} | |
}); | |
bot.login(TOKEN); | |
// a wise man once told me to always add a newline after the end of a file because it confuses some interpreters | |
// What i like; the indents are consistent and logical, some variable names like embed are clear and concise, as well as set to be constant which makes sense. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment