我只获得了第一个“ moneybag” 表情符号来响应频道中的最新消息,即机器人发送的嵌入消息,但是,我希望机器人对消息进行响应新嵌入了“钱袋子” 和“门票” 表情符号,到目前为止,它会与“钱袋子” 表情符号反应,但是,尝试对“门票” 表情符号做出反应时出错。如何让机器人对带有两个表情符号的新嵌入内容做出反应?
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.');
});
}
答案 0 :(得分:1)
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('?')
答案 1 :(得分:0)
第一个import React from 'react';
import styled from 'styled-components';
const Container = styled.div `
display: flex;
border: solid black 3px;
flex: 1;
`
const DashBorder = styled.div `
width: 10%;
border-right: 2px shadow solid black;
background-color: blue;
`
const OtherContent = styled.div `
width: 90%;
background-color: red;
`
class DashBar extends React.Component {
render() {
return (
<Container>
<DashBorder>Dash</DashBorder>
<OtherContent>Other</OtherContent>
</Container>
);
}
}
export default DashBar
实际上返回一个MessageReaction对象,这就是为什么出现此错误的原因(无法在MessageReaction上调用.then()
)。
您可以 1。使用异步/等待
.react()
或 2。使用async function() {
const embed = await message.channel.send('test')
await embed.react('?')
await embed.react('?')
}
的{{1}}属性
message