Answer the question
In order to leave comments, you need to log in
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
how you write code is how it will run, without any extra magic.
message.channel.send().then(msg => {
msg.delete({ timeout: 60000 })
})
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() )
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 questionAsk a Question
731 491 924 answers to any question