【发布时间】:2018-09-13 09:54:22
【问题描述】:
我不太懂Javascript,所以请多多包涵。
所以,我正在尝试为我的 Discord Bot 发出命令。基本上,我想要发生的是,当您发布“!records”时,我希望机器人发送一个 RichEmbed,其中包含您可以选择的 2 个选项。
if (message.content.startsWith(config.prefix + 'records')) {
const embed = new Discord.RichEmbed()
.setTitle('D E I C I D E Records')
.setAuthor('D E I C I D E', 'https://cdn.discordapp.com/attachments/430238345826664448/430504575502385154/logo.png')
.setColor(3447003)
.setDescription('Please select an option.')
.setTimestamp()
.addField('1. Raid Wins', 'Respond with "1" for Raid Wins.')
.addField('2. Defense Wins', 'Respond with "2" for Defense Wins.')
message.channel.send({embed})
我已经确定了那部分。它正是我想要的。它发送带有两个选项的 RichEmbed。
接下来我想要发生的是,当您发送“1”或“2”时,我希望机器人回复正确的记录。这是我无法正确处理的部分。以下是所有代码:
if (message.content.startsWith(config.prefix + 'records')) {
const embed = new Discord.RichEmbed()
.setTitle('D E I C I D E Records')
.setAuthor('D E I C I D E', 'https://cdn.discordapp.com/attachments/430238345826664448/430504575502385154/logo.png')
.setColor(3447003)
.setDescription('Please select an option.')
.setTimestamp()
.addField('1. Raid Wins', 'Respond with "1" for Raid Wins.')
.addField('2. Defense Wins', 'Respond with "2" for Defense Wins.')
message.channel.send({embed})
message.channel.awaitMessages(response => response.content === '1', {
max: 1,
time: 10000,
errors: ['Ran out of time!'],
})
message.channel.send(drecords.RaidWins)
message.channel.awaitMessages(response => response.content === '2', {
max: 1,
time: 10000,
errors: ['Ran out of time!']
})
message.channel.send(drecords.DefenseWins)
} else
目前,当您发布“!记录”时,它会发送 RichEmbed,但也会发送记录,而不是等待回复。
谁能概述一下我在这里做错了什么?
另外,我希望能够说一个命令来更新记录,而无需进入 Bot 的文件并手动执行。
if (message.content.startsWith(config.prefix + 'updateraids')) {
let newRecords = message.content.split(" ").slice(1, 2)[0];
drecords.RaidWins = newRecords;
fs.writeFile('./drecords.json', JSON.stringify(drecords), (err) => console.error);
} else
if (message.content.startsWith(config.prefix + 'updatedefenses')) {
let newRecords = message.content.split(" ").slice(1, 2)[1];
drecords.DefenseWins = newRecords;
fs.writeFile('./drecords.json', JSON.stringify(drecords), (err) => console.error);
}
目前,当您说出这些命令中的任何一个,然后说出一些文本时,例如“!updatedefenses DefenseWin2”,它会替换第一个字符串 (DefenseWin1),而不是在 Bot 的文件中添加另一个字符串。我将如何删除一个条目而不是添加一个条目?对不起,如果这里有点太多,想把它们都挤到一篇文章中,因为它们都是相关的。
我已经完成了好几个小时的研究,浏览了其他 Stackoverflow 问题、浏览了 Discord.js 和 An Idiot's Guide YouTube 教程,但没有运气。
我们将不胜感激。
【问题讨论】:
标签: javascript discord discord.js