我有代码可以创建一个反应菜单,然后输出用户选择的任何选项
client.on('message', async message => {
if (message.author.bot) return;
if (message.content === 'y.Einek')
{
const sentMessage = await message.channel.send(Einek);
const reactions = ['?', '?', '?'];
for (const reaction of reactions) await sentMessage.react(reaction);
const filter = (reaction, user) => reactions.includes(reaction) && user.id === message.author.id;
const collected = await sentMessage.awaitReactions(filter, { max: 1, timeout: 5000, errors: ['time'] }).catch(() => null);
if (!collected) return message.channel.send('You either took too long or something went wrong selecting your difficulty.');
const { name } = collected.first().emoji;
const response = name === '?' ? 'Normal' : (name === '?' ? 'Hard' : 'Extreme');
return message.channel.send(response);
}
});
一切正常,只是不输出“响应”
答案 0 :(得分:0)
这段代码应该可以工作。对任何错误使用 catch 方法。
client.on('message', async message => {
if (message.author.bot) return;
if (message.content === 'y.Einek') {
const sentMessage = await message.channel.send(Einek);
const reactions = ['?', '?', '?'];
for (const reaction of reactions) await sentMessage.react(reaction);
const filter = (reaction, user) => reactions.includes(reaction) && user.id === message.author.id;
sentMessage.awaitReactions(filter, { max: 1, timeout: 5000, errors: ['time'] }).then(collected => {
const { name } = collected.first().emoji;
const response = name === '?' ? 'Normal' : (name === '?' ? 'Hard' : 'Extreme');
sentMessage.channel.send(response);
}).catch(() => message.channel.send('You either took too long or something went wrong selecting your difficulty.'));
}
});