Discord.js尝试发送嵌入,但只发送空消息

时间:2017-05-30 14:39:19

标签: javascript node.js discord

我尝试向我的频道发送嵌入消息,因此当我输入

**embed

在我的频道中,它应该返回嵌入消息,如

testbot    Title
           Description

但它只是从我的testbot(机器人名称)返回一条空消息。我尝试使用

  

message.channel.send(embedd,embed);

相反,但它给我一个错误,说嵌入是没有声明。 .send(内容,选项)是格式,嵌入是选项。

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);

我的代码在上面,任何想法有什么不对?将var更改为const也没有任何作用。

4 个答案:

答案 0 :(得分:2)

将变量重命名为embed并使用此格式

case "embed":
    var embed = new Discord.RichEmbed()
        .addField("Title", "Description")
    message.channel.send({embed});
        // .catch(console.error);
    break;

答案 1 :(得分:0)

这应该有效

case "embed":
    var embed = new Discord.RichEmbed()
    .setTitle(`Title`)
    .setDescription(`Desc`)
    .addField("Title", "Description")
    message.channel.sendEmbed(embed);
    // .catch(console.error);
    break;

答案 2 :(得分:0)

使用此格式:

void handleGenericMessage(struct GenericMessage* msg){
    switch(msg->type){
        case AType:
            handleA(msg->a);
            break;
        case BType:
            handleB(msg->b);
            break;
}

现在不建议使用message.channel.send({ embed: embedd }) 进行发送的方法。对于使用send事件的嵌入,您需要将其指定为使用sendEmbed的嵌入,否则它将返回一个空消息,这将(将来)使机器人退出。

答案 3 :(得分:0)

let embed = new Discord.RichEmbed()
    .setColor(0x00AE86)
    .addField("Title", "Description")
    .setTimestamp()
if(!args[0]) return message.channel.send(embed);

这就是我用来在机器人上嵌入所有内容的方法。

相关问题