javascript - Discord JS - 如何对同一个嵌入做出多次反应?
问题描述
我只得到了第一个“钱袋”表情符号来对频道中的最新消息做出反应,这是机器人发送的嵌入,但是,我希望机器人对“钱袋”和“钱袋”的新嵌入做出反应“票”表情符号,到目前为止,它会与“钱袋”表情符号做出反应,但是当它试图与“票”表情符号做出反应时会出错。如何让机器人对两个表情符号的新嵌入做出反应?
if (message.content === '-new') {
const filter = (reaction, user) => {
return ['', ''].includes(reaction.emoji.name) && user.id === message.author.id;
};
const embed = new Discord.RichEmbed()
.setTitle('Ticket')
.setColor('DC3BF5')
.setDescription('Thank you for showing interest in purchasing a commission from the Quadra Build Team, or for lending us your time through Support. Make sure you have read our #terms-of-service channel before requesting a commission. We are glad to make your prolific ideas & requests come true!\n\n If you accidentally created a ticket by mistake, use (-del) to delete the ticket.\n\n React with :moneybag: to order a Commission.\n React with :tickets: to create a Support Ticket.\n -------------------------------------------------------------------------------------------------')
message.channel.send(embed)
.then(m => m.react(''))
.then(m => m.react(''))
.catch(m => {
console.error('Emoji failed to react.');
});
message.awaitReactions(filter, { max: 1, time: 0, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '') {
collected.on('collect', () => {
m.clearReactions();
var secondEmbed = new Discord.RichEmbed()
.setTitle('Ticket')
.setColor('DC3BF5')
.setDescription('lol')
});
} else {
collected.on('collect', () => {
m.clearReactions();
var secondEmbed = new Discord.RichEmbed()
.setTitle('Ticket')
.setColor('DC3BF5')
.setDescription('lol 2')
});
}
})
.catch(collected => {
message.channel.send('You didn\'t react with either of the specified emojis.');
});
}
解决方案
Message#react 在 Promise 中返回 MessageReaction,因此您需要执行以下操作:
message.channel.send(embed)
.then(m => m.react(''))
.then(m => m.message.react(''))
或者
message.channel.send(embed)
.then(m => {
m.react('')
m.react('')
});
或使用异步等待:
const m = await message.channel.send(embed);
await m.react('')
await m.react('')
推荐阅读
- arrays - 尝试遍历数组时未定义的局部变量或方法
- c++ - C++ 使用参数包的声明
- reactjs - 在反应中将变量从一个文件导出到另一个文件
- javascript - Mapbox-gl-js 自定义图层 - 使用threejs 渲染器清除时背景地图变白
- matlab - 为什么我的 MATLAB 程序不能执行 if 语句块?
- python - 如何循环遍历具有差异行的表?例如这是输入 ([[0,4],[2,4],[-1,3]] 我想要的输出是这个 [[0,1.5],[2,1.5],[1.5,3] ]
- ios - 重命名Xcode项目flutter后无法构建iOS
- opencv - 如何在特定距离内沿边缘填充颜色
- css - 为什么 mdbootstrap 列没有占用整个页面的响应宽度?
- python - Django:实现多个用户级别/角色/类型