I
I
Ilya Zholudev2021-02-27 19:09:30
Node.js
Ilya Zholudev, 2021-02-27 19:09:30

How can a Discord bot delete a message after a minute?

Good day, I want to delete a message after it has been sent after a certain period of time.
In addition to this, it’s not clear to me, after this time, the last message in the channel will be deleted, if so, then probably you need to specify the message ID? In any case, I haven't found an answer to my question yet.
Tell?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2021-02-27
@Astroreen

how you write code is how it will run, without any extra magic.

message.channel.send().then(msg => {
    msg.delete({ timeout: 60000 })
})

I
Israfil22, 2021-02-27
@Israfil22

If you receive a message from the 'message' event, then a message object is passed to that event handler.
It has a delete method.
The function to create a delayed procedure in js is setTimeout() .
If the message object is not available for some reason, it must be retrieved accordingly.
Each Discord API entity has its own unique key. Role, user, and even messages.
Judging by the question, this is a specific message.
If you have previously had a message object, write down its id field somewhere.

// channel - объект канала, snowflake - id сообщения
channel.messages.fetch(snowflake)
    .then( message => message.delete() )

Don't forget to check for undefined in then and other cases.
If the message hasn't previously appeared anywhere (in any event handler such as message), then you'll have to search through the channel's messages.
Either dynamically
Or from the cache

V
Vadim087, 2021-02-28
@Vadim087

you can do this
msg.delete( 60000);
possible
if (msg.author.id === " user id " ) { msg.delete( 60000);}
possible
if (msg.author.id === " user id " || " other users " ) { msg. delete( time in milliseconds );}
bonus
message output delay 5 seconds
setTimeout(() => {
msg.reply( " " )
// console.log ( " " );
} , 5000 );
}
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question