【问题标题】:Getting error when trying to edit my bot message with discord.js尝试使用 discord.js 编辑我的机器人消息时出错
【发布时间】:2019-09-10 17:13:35
【问题描述】:

我想编辑机器人发送的消息。

我想我已经找到了怎么做,但我的编辑说 .edit 类型 message[] 上不存在。

我做错了什么?

   msgObject.channel.send('my emote').then((msg)=>{
   setTimeout(function(){
   msg.edit('my others emotes');}, 1000)};

感谢您的帮助。

【问题讨论】:

    标签: typescript discord.js


    【解决方案1】:

    我的代码运行良好:

    message.channel.send("test").then(msg => { 
        setTimeout(function() { 
            msg.edit('new test'); 
        }, 5000) 
    });
    

    也许您的msg 导致了您的错误,因此请尝试将其更改为其他内容。 此外,您的代码存在括号问题(没有足够的右括号)。

    previous question 中,有人建议您的 Discord.js 或 NodeJS 可能已过期,这可能会导致错误。 Comment

    【讨论】:

      【解决方案2】:

      我的代码有效:

      msgObject.channel.send('My message').then(msg =>{
         setTimeout(() => {
            if(msg instanceof Message){
               msg.edit('My other nessage')
            }
         }, 1000)
      })
      

      https://www.typescriptlang.org/docs/handbook/advanced-types.html#instanceof-type-guards

      【讨论】:

        【解决方案3】:

        您的message.channel.send("test")message 似乎正在返回一系列消息。因此,您需要首先选择其中一条消息。 if you look on the docs you can see that it either returns a message or a message array。为什么会这样,我不知道,但希望你能从那里走得更远。

        【讨论】:

          猜你喜欢
          • 2020-09-08
          • 2022-11-14
          • 1970-01-01
          • 2021-05-08
          • 1970-01-01
          • 2023-03-29
          • 1970-01-01
          • 1970-01-01
          • 2018-06-05
          相关资源
          最近更新 更多