【问题标题】:Discord.JS Bot Delete Own MessageDiscord.JS 机器人删除自己的消息
【发布时间】:2021-01-17 22:27:37
【问题描述】:

试图让机器人发送消息,然后在 30 秒后删除它自己的消息。 自从我收到此错误以来,任何人都可以帮忙

TypeError:无法读取未定义的属性“删除”

代码

message.channel.send('<@' + message.author.id + '>, the email you provided is not valid, sorry.')
            .then(function (message) {
              message.react("????")
              message.react("????")
            })
            .then(message => {
                message.delete({ timeout: 10000 /*time unitl delete in milliseconds*/});
            })
            .catch(console.error);

【问题讨论】:

  • 我不确定,但是当您首先调用 .then 时,消息对象已经被使用,因此当您使用 .then 时,什么都没有了。您可以尝试在第一个 .then 方法中使用 message.delete 吗?
  • 太棒了,这很简单!谢谢 - 修复了它:-) 我没有意识到是这样的。你想作为答案发布,以便我接受:)

标签: javascript discord.js


【解决方案1】:

当您使用.then 方法时,message 对象已经被使用,并且当您调用第二个.then 方法时没有任何剩余,并且在带有选项的消息上使用.delete 可能是不和谐的全局。 js 消息对象,因此您可能可以在第一个 then 块中调用它。

message.channel.send('<@' + message.author.id + '>, the email you provided is not valid, sorry.')
            .then(function (message) {
              message.react("?")
              message.react("?")
              message.delete({ timeout: 10000 /*time unitl delete in milliseconds*/});
            })
            .catch(console.error);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-29
    • 2021-08-06
    • 1970-01-01
    • 2018-12-29
    • 2021-07-27
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    相关资源
    最近更新 更多