Send message and shortly delete it

牧云@^-^@ 提交于 2020-01-11 06:59:09

问题


I'm trying to make a Discord bot delete its "system messages" after, say, 10 seconds, because I've been seeing a lot of "Invalid command" errors and "Done!" notifications, and I'd like to clear them out for actual messages. This is different from deleting messages where the user has a command; I already have that capability.


回答1:


I recommend you send the message, wait for the response and delete the returned message after that time. Here's how it'd work:

message.reply('Invalid command')
  .then(msg => {
    msg.delete(10000)
  })
  .catch(/*Your Error handling if the Message isn't returned, sent, etc.*/);

As you can read from the Docs, you can just pass a value in Milliseconds to Message.delete() as a timeout.



来源:https://stackoverflow.com/questions/46907207/send-message-and-shortly-delete-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!