虽然我只调用过一次,但似乎代码块在 1 次尝试后运行了 1 次以上
代码的功能是等待一个反应然后等待一个消息并将该消息保存在一个 .json 文件中
main.js
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLocaleLowerCase();
if (command == story) {
client.commands.get('story').execute(message, args, Discord, client, fs);
}
});
命令 story.js
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.message.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id = channel) {
if (reaction.emoji.name === emoj) {
const filter = m => {
return m.author.id === message.author.id;
}
message.channel.send('Input Story').then(msg => {
msg.channel.awaitMessages(filter, {
max: 1,
time: 30000
})
.then(swag => {
swag = swag.first()
client.msgs[swag.author.username] = {
message: swag.content
}
fs.writeFile("./Database/msgs.json", JSON.stringify(client.msgs, null, 4), err => {
if (err) throw err;
message.channel.send("logged");
});
})
})
}
}
else {
return;
}
});
});