编辑命令执行程序的命令后,机器人如何编辑其消息?


if(message.content === "hello") {
message.channel.send("World");
}
if(message.content === "hi") {
message.channel.send("There");
}

我正在为我的机器人尝试一项新功能,但我不完全确定如何启动它。所以我有关于此消息的命令。所以我要做的是,当我向机器人发送Hello时,它会回答World,如果我编辑消息以hi机器人也会编辑它的消息;从WorldThere.

不和谐.js版本:12.2.0

这不是一个稳定的解决方案,因为在这种情况下没有正确的方法来编辑机器人的消息,因此您只需在编辑消息的通道中获取机器人的最后一条消息并对其进行编辑。

您必须像这样使用messageUpdate事件:

client.on('messageUpdate', async (oldMessage, newMessage) => {
if (oldMessage.content === 'hello' && newMessage.content === 'hi') {
const messages = await newMessage.channel.messages.fetch()
const lastMsg = messages.filter((msg) => msg.author.id === client.user.id).first()
lastMsg.edit('there')
}
})

你应该做这样的事情。我累了,它有效。

client.on('messageUpdate', (oldMessage, newMessage) => {

if (newMessage.content === "hello") {
message.channel.send("World");
}
if (newMessage.content === "hi") {
message.channel.send("There");
}

})

您也可以将其与删除上一条消息结合起来。

最新更新