简体   繁体   English

如何将 discord 消息定义为字符串或变量?

[英]How to define a discord message as a string or variable?

I'm making a Discord bot that can put peoples' messages into different types of categories to respond to.我正在制作一个 Discord 机器人,它可以将人们的消息放入不同类型的类别中进行响应。 For some reason it keeps suggesting that the Discord.Message.content is undefined when I try to run it.出于某种原因,当我尝试运行它时,它一直提示Discord.Message.content undefined

I've tried searching up if I was defining it correctly and couldn't find much.我已经尝试搜索是否正确定义它并且找不到太多。 I'm doing this with Brain.js:我正在使用 Brain.js 执行此操作:

const network = new brain.recurrent.LSTM(); 

const trainingData = data.map(item => ({
    input: item.message,
    output: item.category
}));

network.train(trainingData, {
    interations: 2000
});

bot.on('message', msg =>{
    const raw = network.run(Discord.Message.content)
});

Replace this:替换这个:

bot.on('message', msg =>{
    const raw = network.run(Discord.Message.content)
})

with this:有了这个:

bot.on('message', msg =>{
    const raw = network.run(msg.content)
})

Discord.Message is the type of object (aka "class"), whereas msg is the object itself. Discord.Message是 object(又名“类”)的类型,而msg是 object 本身。 The docs will refer to Message objects, which msg is one of, but to access the content of a specific message you need to use the variable holding that specific message, which is msg .文档将引用Message对象,其中msg是其中之一,但要访问特定消息的内容,您需要使用保存该特定消息的变量,即msg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM