Javascript 如何让机器人在不协调时编辑自己的消息

Javascript 如何让机器人在不协调时编辑自己的消息,javascript,discord,discord.js,message,edit,Javascript,Discord,Discord.js,Message,Edit,我的朋友为我写了这个惊人的代码,但它似乎不起作用。这意味着通过命令发送消息,然后反复编辑消息。但当我运行代码时,我的终端显示 DiscordAPIError:无法编辑由其他用户方法编写的消息:“补丁”,路径:“/channels/80830040607065483/messages/811398346853318668”,代码:50005,httpStatus:403 有办法解决这个问题吗 client.on('message',userMessage=> { 如果(userMessage.co

我的朋友为我写了这个惊人的代码,但它似乎不起作用。这意味着通过命令发送消息,然后反复编辑消息。但当我运行代码时,我的终端显示

DiscordAPIError:无法编辑由其他用户方法编写的消息:“补丁”,路径:“/channels/80830040607065483/messages/811398346853318668”,代码:50005,httpStatus:403

有办法解决这个问题吗

client.on('message',userMessage=>
{
如果(userMessage.content=='hi')
{
botMessage=userMessage.channel.send('hi there')
编辑(“你好”);
botMessage.edit(“what up”);
botMessage.edit(“sup”);
botMessage.react(“:clap:”)
}
});
通道发送()方法返回一个承诺,这意味着您必须等待操作完成后才能定义它。这可以使用
.then()
async
wait
来完成。从个人偏好来看,我经常使用第二种选择,尽管我已经为您列出了两种选择

最终代码
谢谢@Bqre。我试过这个,多亏了你,效果非常好。谢谢你帮我省去了挠头的时间。lol client.on('message',async userMessage=>{if(userMessage.content=='hi'){botMessage=wait userMessage.channel.send('hi there')wait botMessage.edit(“你好”);wait botMessage.edit(“what up”);botMessage.edit(“sup”);botMessage.react('
client.on('message', async userMessage => {
  if (userMessage.content === 'hi') 
    {
        /*
          botMessage = await userMessage.channel.send('hi there')
        */
        userMessage.channel.send('hi there').then(botMessage => {
          await botMessage.edit("hello");
          await botMessage.edit("what up");
          botMessage.edit("sup");
          botMessage.react(":clap:")
        })
    }
});