ツtanni
ツtanni

Reputation: 31

Discord embed message not working correctly

My discord bot is sending the wrong embed message. Its a hug command, if someone doesn't mention somebody the bot sends an error message in the channel with the following content: Please mention a valid user! I want to send this message as a embed, but its not working correctly. Everytime i use the command without mentioning someone i don't get an error in my console. When i mention someone it works, but it sends the Error message as well. Here's a screenshot: https://i.sstatic.net/YgAmC.png

My code:

const Discord = require('discord.js');
const prefix = require('../config.json');
const hugGif = require('./Huggifs.json');

module.exports = {
    name: "hug",
    description: "Posts a hug gif.",
    aliases: ['hug'],
    execute(client, message, args) {

        if (!message.mentions.users.first())
        return message.channel.send();
        const aembed = new Discord.MessageEmbed()
        .setColor('BLUE')
        .setTitle(`**Please mention a valid user!**`)
        message.channel.send(aembed);

    const gif = hugGif[Math.floor(Math.random() * hugGif.length)];
        const embed = new Discord.MessageEmbed()
        .setColor('BLUE')
        .setTitle(`${message.author.username} hugs ${message.mentions.users.first().username}!`)
        .setImage(gif)
        .setFooter( `Requested by ${message.author.username}`)
        .setTimestamp()
        message.channel.send(embed);
    },
};

Please help me, thank you!

Upvotes: 0

Views: 2614

Answers (1)

Toasty
Toasty

Reputation: 1880

Your problem is this line:

return message.channel.send();

There are two problems:

  1. If there are no mentions in the message, you immediately call return. Anything below that return statement will not be executed
  2. You are calling .send() empty

You sould create your embed first and then return message.channel.send(<embed>).

Your if statement also looks strange, you should do it like this:

const mentionedMember = message.mentions.users.first();

if(!metionedMember) {
   // create you embed here
   return message.channel.send("your embed here");
}

// do things if there is a mention inside the message

Upvotes: 3

Related Questions