How to make a bot send dms after some time?

hello! I just started coding like two days ago and I want to make a discord bot that is able to send anonymous dms, I already have the code to send the messages instantly thanks to a youtube tutorial but I was wondering if you could somehow make the bot wait a certain amount of time before sending the message, this is the code I have for the instant dm if it helps with anything

    client.on ('message', message =>{

            if (message.author.bot) return;

            

            mention = message.mentions.users.first(); 

            

            if (message.content.startsWith (prefix + "send") ) {

                if (mention == null) { return; } 

                message.delete();

                mentionMessage = message.content.slice (5);

                mention.send('someone sent you a letter! **||** ' + mentionMessage + ' **||** make sure to send them a reply! (if you know who they are of course ^^)');

                message.channel.send ('your letter will be delivered!')

            } },)

I

1 Like
var sendmsg = function(){
mention.send('someone sent you a letter! **||** ' + mentionMessage + ' **||** make sure to send them a reply! (if you know who they are of course ^^)');
};
setTimeout(sendmsg,3000); //Send the message after 3 seconds.
1 Like

is there a specific place where I have to write it?
I’ve been trying to do it and I kinda understand how it works but I havent been able to really make it work

Add it to the Ready on Message event.

ok sorry Im a huge dumbass, I’ve been trying to find the ready on the message event but I can really seem to find it,Im really sorry but can you describe it more specifically please?

This:

client.on ('ready', () =>{

ooooooh alright so do I do something like this?

client.on (‘ready’, () =>{
var sendmsg = function(){
mention.send(‘someone sent you a letter! || ’ + mentionMessage + ’ || make sure to send them a reply! (if you know who they are of course ^^)’);
};
setTimeout(sendmsg,3000);
}

1 Like

Yes, something like that, not quite there yet

1 Like

what do you mean something like that?
sorry, this is just hard to figure out
I already tried a bunch of option but it either sends instantly or breaks everything

I don’t think I should keep on spoon feeding you at this point.
To fix it you have to change something, not everything in the code is correct

ok ok I’ll try to figure it out
thank you ^^

2 Likes

I’ve been trying to look for some coding , I want my bot to send private dms but juss like private dms and I’m not sure how to code that can someone help me ?

Don’t bump. Make a new topic.