问题
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