Last active
April 17, 2024 03:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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