检查是否有人回复了discord.js中的bot



我正在制作一个提问机器人。如何检查某个用户是否回复了它?(用户A会说"!问@UserB"Bot会说@UserB,请回答这个问题用户b会回复。)我知道一般的代码可以工作,但是我需要一种方法来检查回复和它们的内容。

代码:

module.exports = {
name: 'ask',
description: 'asks a question',
async execute(message, args) {
if (!args[0]) {
message.reply("Specify User");
} else {
message.channel.send(args[0] + " Please answer the question."); // args[0] will be the user
}
}
}

所有消息都有一个message_reference属性。这包含了公会,频道和消息id。如果不是回复,则此属性为空。我想你已经知道这个频道了。

//async function
//message is an instance of Message
let { channel, message_reference: reply } = message
const repliedTo = await channel.messages.fetch(reply.message_id);
//repliedTo is now the replied message with author, content, etc
if(repliedTo.author.bot) {
//replied messages author is a bot
}

抄自我的答案

最新更新