javascript - Discord.js 'awaitReactions 不是函数' 错误
问题描述
当用户单击机器人嵌入的表情符号时,我试图让机器人做出反应。
我在控制台中收到:
UnhandledPromiseRejectionWarning:TypeError:chestEmbed.awaitReactions 不是函数
编码:
module.exports = {
name: 'enterhouse',
aliases: 'eh',
permissions: ["ADMINISTRATOR", "MANAGE_MESSAGES", "CONNECT"],
description: "Pick a number",
async execute(client, message, args, Discord){
const chestEmbed = new MessageEmbed()
.setColor('#FFA500')
.setImage('https://imageURL.jpg');
message.channel.send(chestEmbed).then(chestEmbed => {chestEmbed.react('1️⃣').then(() => chestEmbed.react('2️⃣').then(() => chestEmbed.react('3️⃣')))}
)
.catch(() => console.error('One of the emojis failed to react.'));
const filter = (reaction, user) => {
return (['1️⃣', '2️⃣', '3️⃣'].includes(reaction.emoji.name) && user.id === message.author.id);
};
chestEmbed.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '1️⃣') {
chestEmbed.delete();
message.reply('you reacted with 1');
} else if (reaction.emoji.name === '2️⃣') {
message.reply('you reacted with 2');
} else {
message.reply('you reacted with 3');
}
})
.catch(collected => {
message.reply('Time is up, you did not react.');
});
}
}
当它是 message.awaitReactions 时它工作得很好。
非常感谢任何帮助!
解决方案
您正在等待来自嵌入的消息,它本身不是嵌入的消息。
简单修复:
...
chestEmbed = await message.channel.send(chestEmbed)
...
完整代码:
module.exports = {
name: 'enterhouse',
aliases: 'eh',
permissions: ["ADMINISTRATOR", "MANAGE_MESSAGES", "CONNECT"],
description: "Pick a number",
async execute(client, message, args, Discord) {
const chestEmbed = new MessageEmbed()
.setColor('#FFA500')
.setImage('https://imageURL.jpg');
chestEmbed = await message.channel.send(chestEmbed)
chestEmbed.react('1️⃣').then(() => chestEmbed.react('2️⃣')).then(() => chestEmbed.react('3️⃣'))
const filter = (reaction, user) => {
return (['1️⃣', '2️⃣', '3️⃣'].includes(reaction.emoji.name) && user.id === message.author.id);
};
chestEmbed.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '1️⃣') {
chestEmbed.delete();
message.reply('you reacted with 1');
} else if (reaction.emoji.name === '2️⃣') {
message.reply('you reacted with 2');
} else {
message.reply('you reacted with 3');
}
})
.catch(collected => {
message.reply('Time is up, you did not react.');
});
}
}
推荐阅读
- mule - Mule 4 - 直到成功 - 增加每次迭代的等待时间
- parquet - 编写 Parquet 文件时如何指定分区数?
- amazon-web-services - AWS Amplify 与在弹性 beanstalk 中创建的 ec2 中的 rest api 交谈
- laravel - 有没有办法删除 Laravel URL 中的 %20 ?
- javascript - 按属性值从深度嵌套的对象数组中删除对象
- postgresql - 在 Postgresql 中存储格式化时间戳的最佳方法是什么
- vuetify.js - 如何使用 nuxt 在 vuetify 插件中使用roboto字体提高页面速度
- laravel - 如何在 laravel 黄昏测试用例中向下滚动窗口
- reactjs - React 中的事件驱动方法?
- php - WooCommerce 中特定购物车小计的免费赠品产品