![](/img/trans.png)
[英]Discord Bot replying to itself, doesn't recognize message.author.bot
[英]Bot not replying correctly in a private message
因此,此代码块是游戏者A(挑战者)向游戏者B(目标)发出挑战的代码的一部分。 机器人向玩家B发送一条私人消息,告诉他们他们受到挑战,并询问他们是否接受或拒绝挑战。
以下代码似乎没有响应玩家B的回复。
if (message.channel.id === '541736552582086656') return target.send("Do you accept the challenge? Please reply with 'accept' or 'deny'.")
.then((newmsg) => {
newmsg.channel.awaitMessages(response => response.content, {
max: 1,
time: 150000,
errors: ['time'],
}).then((collected) => {
if (collected === 'accept') {
newmsg.channel.send("You have ***accepted*** the challenge. Please wait while your battlefield is made...");
} else if (collected === 'deny') {
newmsg.channel.send("You have ***denied*** the challenge.")
}
}).catch(() => {
newmsg.channel.send('Please Accept or Deny the challenge.');
});
});
}
在此代码块之前,我设置了将消息记录到服务器上的通道,向质询者和目标发送质询信息。 该漫游器通过pm成功联系了他们所挑战的目标,但是回复(即使回复“接受”时仍会认为该请求已被拒绝)。
感谢您提供的所有帮助!
扩展@Stock Overflaw的答案后, awaitMessages
将始终返回获取的消息的集合,这意味着collected === 'accepted'
将不起作用。 您正在检查集合对象是否与字符串相同。
您需要的是从集合中获取第一条消息(仅在您的情况下),并根据字符串检查其内容。 在下面,您可以找到重新编写的.then(...)
语句。 试试看,让我知道结果如何。
ps您的收藏夹过滤器将无法正常工作。 过滤器仅检查是否将消息添加到集合中。 由于您的“过滤器”是response => response.content
,因此它将仅检查response.content
是否为空, null
或undefined
.then((collected) => {
// Grabs the first (and only) message from the collection.
const reply = collected.first();
if (reply.content === 'accept'){
reply.channel.send("You have ***accepted*** the challenge. Please wait while your battlefield is made...");
} else if (reply.content === 'deny') {
reply.channel.send("You have ***denied*** the challenge.")
} else {
reply.channel.send("Your response wasn't valid.");
/*
* Code here to handle invalid responses
*/
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.