[英]How to display or use variables in Discord.RichEmbed()
I am not able to include variables within a richembed on my Discord bot. 我无法在Discord机器人的Richembed中包含变量。
I'm an absolute noob to Javascript and Discord bots. 对于Javascript和Discord机器人,我绝对是菜鸟。 I have tried putting the code within the richembed (which doesn't work at all..) and placing the embeds at the bottom of the javascript file, amongst other things.
我试过将代码放在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.', '_ _')
I'd expect the embedded page to print the modelInfo variable, however Node.JS crashes saying "modelInfo is not defined", even though it is defined as shown above. 我希望嵌入式页面可以打印出modelInfo变量,但是Node.JS崩溃时说“未定义modelInfo”,即使它的定义如上所示。
The embedModelInfo definition needs to go in between the modelInfo definition and the message.channel.send(embedModelInfo)
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.