Skip to content

Instantly share code, notes, and snippets.

@Jeydin21
Last active April 17, 2024 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeydin21/e6af85c510aeb5bebe4c3afa928c5f9d to your computer and use it in GitHub Desktop.
Save Jeydin21/e6af85c510aeb5bebe4c3afa928c5f9d to your computer and use it in GitHub Desktop.
Code for a Discord bot that sends a message at an interval in a channel in a server
const Discord = require('discord.js'); // This code is for discord.js v12 because idk how to use v14
const client = new Discord.Client();
require('dotenv').config();
client.on('ready', () => {
console.log("Logged in as: " + client.user.tag);
const serverId = ''; // Server ID of the server the channel is in
const channelId = ''; // Channel ID of the channel you want the bot to send messages to
const message = ''; // Message you want the bot to send
const interval = 5000; // Interval in milliseconds
setInterval(() => {
const channel = client.guilds.cache.get(serverId)?.channels.cache.get(channelId);
if (channel && channel.type === 'text') {
channel.send(message);
}
}, interval);
});
client.login(process.env.TOKEN);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment