2017-05-30 76 views
-1

我想送我的頻道的嵌入信息,所以當我在信道類型Discord.js嘗試發送嵌入,而只是將空消息

**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也不起作用。

回答

2

變量重命名爲embed和使用這種格式

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

我只是嘗試這樣做,它仍然打印一個空字符串,雖然它不給我棄用錯誤了。 –

+0

你打印空字符串是什麼意思?當我單獨嵌入**時,它會提供http://prntscr.com/fdvcfa,正如您所描述的那樣。或者我錯過了一點? @Mad_Questionnaire – Wright

+0

我覺得有人在我的系統被竊聽,機器人似乎並不打印東西,但爲你工作,打印此http://puu.sh/w5DFa/3a79b4fd17.png –

0

這應該工作

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