[英]How to display or use variables in Discord.RichEmbed()
我无法在Discord机器人的Richembed中包含变量。
对于Javascript和Discord机器人,我绝对是菜鸟。 我试过将代码放在richembed中(这根本不起作用..),并将嵌入内容放在javascript文件的底部等。
// Get information on models
if (msg.content.startsWith('!info')) {
// Get first (category) argument and 2nd (model name) category
const args = msg.content.slice('!info'.length).split(' ');
const command = args.shift().toLowerCase();
// Set arguments as variables
const cat = args[0]
const model = args[1]
// Check if the model exists in the category
if (fs.existsSync(dirPath + cat + "/" + model)) {
const modelInfo = fs.readFileSync(dirPath + cat + "/" +model, "utf8");
msg.channel.send(embedModelInfo);
} else {
// If it doesn't, display an error
msg.channel.send('ERROR: ' + cat + ' is not a valid category and/or model. Run "!listcat" for a list of categories and to list models within said categories.');
}
msg.channel.send('_ _');
msg.channel.send('READY.');
}
var embedModelInfo = new Discord.RichEmbed()
.setColor('777575')
.setTitle('Model Information')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField(modelInfo, '_ _')
.addField('_ _', '_ _')
.addField('READY.', '_ _')
我希望嵌入式页面可以打印出modelInfo变量,但是Node.JS崩溃时说“未定义modelInfo”,即使它的定义如上所示。
embedModelInfo定义需要介于modelInfo定义和message.channel.send(embedModelInfo)
if (fs.existsSync(dirPath + cat + "/" + model)) {
const modelInfo = fs.readFileSync(dirPath + cat + "/" +model, "utf8");
var embedModelInfo = new Discord.RichEmbed()
.setColor('777575')
.setTitle('Model Information')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField(modelInfo, '_ _')
.addField('_ _', '_ _')
.addField('READY.', '_ _');
msg.channel.send(embedModelInfo);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.