Tuesday 30 May 2017

Discord.js Trying to send embed, but just sends empty message

I'm trying to send my channel an embed message, so when I type

**embed

in my channel it should return the embed message like

testbot    Title
           Description

But it just returns an empty message from my testbot (the bot name). I tried using

message.channel.send(embedd, embed);

instead, but it gives me an error saying embed isn't declared. .send(content, options) is the format and embed is the option.

const Discord = require("discord.js");
const bot = new Discord.Client();
const TOKEN = "MY_TOKEN_ID";
const PREFIX = "**";

var name;
var usrAuth = 0;

bot.on("ready", function() {

    console.log("Ready");
});

bot.on("message", function(message) {

    console.log(message.content);

    if ( message.author.equals(bot.user)) 
        return;

    //  If the message doesn't begin with ** (Our prefix); do nothing 
    if( !message.content.startsWith(PREFIX))
        return;

    var argv = message.content.substr(PREFIX.length).split(" ");
    console.log("argv: "+argv+", argv[1]: "+argv[1]+"");

    // "+VAR_NAME+" Allows you to print a variable
    switch(argv[0].toLowerCase()) {
        case "ping":
            message.channel.send("Ping!");
            break;
        case "embed":
            var embedd = new Discord.RichEmbed()
                .addField("Title", "Description")
            message.channel.sendEmbed(embedd);
                // .catch(console.error);
            break;
        default:
            message.channel.send("Invalid commands");
    }

});

bot.login(TOKEN);

My code is above, any ideas what's wrong? Changing var to const also does nothing.



via Mad_ Questionnaire

No comments:

Post a Comment