How would I make the bot send a message every 24 hours?

Hey, how would I make the bot send a message every 24 hours in a specific channel? Its a discord.js bot. Please may I have the code? Thanks.

I would use UptimeRobot to trigger a command via a HTTP request and run the command with your Discord bot.

So if you haven’t a http server (or express) you should make one something like this

File server.js

const express = require('express');
const app = express();

/* Message configuration */
const guildId = 'guildId';
const channelId = 'channelId';
const message = 'Hello!'

module.exports = bot => {
	/* HTTP Trigger URL*/
	app.get('/dailymessage', (req, res) => {
		var guild = bot.guilds.get(guildId);
		if(guild && guild.channels.get(channelId)){
		} else {
			res.status(404).send('Couldn\'t find the channel or guild');
		res.status(200).send('Message sent');

/* Listener */
const listener = app.listen(process.env.PORT, function() {
	console.log('Your app is listening on port ' + listener.address().port);

And then add this to your bot.js file


Setup your UptimeRobot to HTTP every 24 hours

I don’t know if it is the best approach but it work, I think this is better than a setInterval() or cronjob

1 Like

@Coderholic just use set Interval or store last time you started that timer in a dB and check if time - time in dB = 24 or use node-schedule npm package

Thank you, it worked.

1 Like