我是discordjs软件包的新手,我一直在四处搜寻,但在过去的两天里,我一直陷于此。
我想要实现的是“问卷”,它将指导用户解决一些问题。一个例子是: 用户类型:!askOrder
我所拥有的:
export default Main() {
return (
<Fade in>
<MyComponent />
</Fade>
);
}
但是它只是在询问第二个问题之后停止,而不是捕获/收集第二个答案。我做错了什么?
非常感谢您的回答!
答案 0 :(得分:0)
此答案可能会帮助您:https://stackoverflow.com/a/58901539/11856499。它不使用awaitMessages
,而是使用收集器,它更适合您的问题。
答案 1 :(得分:0)
我要做的是将所有问题(和答案)放在一个数组中,将那些语句包装在一个函数中,然后像这样的循环遍历它们:
protected $spatial = ['lat'];
它有助于稍微清洁一下代码。您可以根据需要更改它们。
我做了一个机器人,问了这样的问题,您可以查看代码here
答案 2 :(得分:0)
您错误地构建了 awaitMessages 事件:
msg.author.send('Do you want red wine or white wine?');
msg.author.send(WineText)
.then((systemMsg) => {
systemMsg.channel.awaitMessages(response => response.content, {
max: 1,
time: 5000,
errors: ['time']
}).then((collected) => {
systemMsg.channel.send(`You want ${collected.first().content}. Do you prefer a verdejo or a rueda?`);
collected.first().channel.awaitMessages(response => response.content, {
max: 1,
time: 10000
}).then((collected2) => {
systemMsg.channel.send(`A ${collected2.first().content} it's. Do you want it at room temperature or chill? `);
}).catch((err) => {
return;
});
});
});
您犯了两个严重错误:
(1) 您向 collected.channel
发送了一条消息。但是,collected
是 collection
的消息,并且没有 channel 属性。要将其发送到频道,只需执行 collected.first().channel
,因为 collected.first()
是一条消息。
(2) 您在代码末尾缺少两个 })
,因为您包含了 then
并且从未关闭。