尝试为我的Word Dictionary机器人修复[object Object]

时间:2020-06-09 18:03:22

标签: javascript object bots discord.js

所以我下载了这个称为单词定义的节点js模块,您可以检查单词定义here

console.log部分,但在message.channel.send部分,效果很好。

console log中存在定义,但是我的机器人消息“ [object Object]”。

let word = arg.slice(0).join(" ");

if (!word) {
 message.reply("\nThat's not how you use a Dictionary nyan~!");
} else {
 const wd = require("word-definition");

 wd.getDef(`${word}`, "en", null, function(definition) {
  message.channel.send(`${definition}`)//This says [object Object]
  console.log(definition);//This works
  /*Console.log example where the word is "dog"
  {
  word: 'dog',
  category: 'noun',
  definition: 'A mammal, Canis lupus familiaris, that has been domesticated for ' 
  +
  'thousands of years, of highly variable appearance due to human ' +
  'breeding.'
  }
  */
});

注意:我正在使用discord.js v12 btw

2 个答案:

答案 0 :(得分:1)

wd.getDef返回具有属性wordcategorydefinition的对象 更改

message.channel.send(defintion)message.channel.send(definition.definition)

可能要将变量重命名为props或其他名称。

答案 1 :(得分:0)

也许尝试像这样使用JSON.stringify():message.channel.send(JSON.stringify(definition))