Skip to content

Reason after blacklisting command Discord.js

I want to add a reason to my blacklists (with the command !blacklist {userid} {reason}) which are visible in the embeds below like .addField (“???? Reason:”, somecode) how can I fix this?

  if (command === "blacklist") {
    if(!config["allowed-users"].includes( return;
    const user = client.users.cache.get(args[0]);
    if(!user) {
      return"This user does not exist")
    if(blacklist.has( {
      return"This user is already on the blacklist")
    blacklist.set(, 'blacklisted');
    let set = db.fetch(`g_${}`);
    var embed = new Discord.MessageEmbed()
    .setTitle(":warning: Blacklisted :warning:")
    .addField("???? Moderator:",
    .addField("???? User:", user.username)
    .addField("???? User ID:",
    .addField("???? Blacklisted on:", message.createdAt)
    .setFooter("© 2020 - 2021 GlobalChat", "")
    .setThumbnail(user.avatarURL({ dynamic:true }))
    .addField("Unblacklist?", "Please contact <@267818548431290369> or <@331736522782932993>");
    client.guilds.cache.forEach(g => {
      try {
      } catch (e) {


First you’ll want to check if there is no reason, this can be simple done by checking, for both approaches, if the second argument is undefined, like so

if (args[1] === undefined) {
    const reason = "No reason.";

This solution will work for both approaches, since if the second argument is undefined there can be no more after it

You could take reason as an argument. Inside the command add

const reason = args[1];

OR if you wanted to have the rest of the blacklist args dedicated to the reason you could add something along the lines of

let reason = ""
for (let i = 1; i < args.length; i++) {
// It's very important that i starts as 1, so we do not take the first argument into account for the reason
    reason += args[i];

And then you can add to the embed

.addField("???? Reason:", reason);

If you went with the first approach, the blacklist command would work like this

!blacklist 012345678910111213 the_reason_here
// or
!blacklist 012345678910111213 reason

The limitation to this approach is that a multi word reason isn’t very intuitive.

If you went with the second approach though, the blacklist command would work like this

!blacklist 012345678910111213 The reason the user was banned and it can go on and on and on as long as the writer wants