机器人回答后删除提示者消息

时间:2019-07-09 18:57:53

标签: javascript node.js discord discord.js

我最近开始创建一个不和谐的bot来娱乐,我试图删除Invocator消息,但徒劳。

我搜索“提示”,并且找到了该主题(Discord.js Delete Single Message)。因此,我使用了他的代码,效果很好,直到出现控制台错误,即:

(node:8012) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message
    at item.request.gen.end (D:\Windows\Documents\discord\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15)
    at then (D:\Windows\Documents\discord\node_modules\snekfetch\src\index.js:215:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:8012) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:8012) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这是我的删除命令:

if (message.content.startsWith(prefix)) {
        message.delete()
            .then(msg => console.log(`Deleted message from ${msg.author.username}`))
            .catch(console.error);
    }

我不知道是什么原因造成的,因为我不使用任何async

(我的消息事件:client.on('message', message => {

谢谢

1 个答案:

答案 0 :(得分:0)

好,所以我找到了解决问题的方法。我只需要向message.delete()

添加超时

因此代码应如下所示:

if (message.content.startsWith(prefix)) {
        message.delete(1000)
            .then(msg => console.log(`Deleted message from ${msg.author.username}`))
            .catch(console.error);
    }

感谢您的帮助。