问题
I've only gotten the first "moneybag" emoji to react to the newest message in the channel, which is the embed that the bot sends, however, I want the bot to react to the new embed with both the "money bag" and "ticket" emojis and so far it will react with the "money bag" emoji but, errors out when it tries to react with the "ticket" emoji. How do I get the bot to react to the new embed with both emojis?
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.');
});
}
回答1:
Message#react returns a MessageReaction in a promise so you need to do:
message.channel.send(embed)
.then(m => m.react('💰'))
.then(m => m.message.react('🎟'))
or
message.channel.send(embed)
.then(m => {
m.react('💰')
m.react('🎟')
});
or with async await:
const m = await message.channel.send(embed);
await m.react('💰')
await m.react('🎟')
回答2:
the first .then()
actually returns a MessageReaction object, which is why you're getting this error (can't call .react()
on a MessageReaction).
You could 1. Use async/wait
async function() {
const embed = await message.channel.send('test')
await embed.react('💰')
await embed.react('🎟')
}
or 2. Use the message
property of MessageReaction
message.channel.send(embed)
.then(m => m.react('💰'))
.then(r => r.message.react('🎟'))
来源:https://stackoverflow.com/questions/58031786/discord-js-how-to-react-multiple-times-to-the-same-embed