2
votes

I am creating a discord bot where it sends a message at a certain time every day to the guild. I am using cron for the scheduled message, but not sure what code to write for the bot to send the message to the 'general' channel of a guild, and if they don't have a 'general' channel, send to the channel with the most activity or messages.

Since defaultChannel was removed, not sure how I should go about this. Also, I don't want to send the message to a specific channel using channel id because I want to make this bot public so a lot of different guilds can use.

 cron.schedule('00 45 12,20 * * *', () => {

      //code to send a message to guild's 'default channel' or 'channel with most activity goes here'
}, {
    scheduled: true,
    timeZone: "America/Los_Angeles"}
);

It doesn't necessarily have to send to 'default' channel or channel with most messages. These are just the options I came up with. Basically, I want the message to go out to just 1 channel where everyone can see it. Any help would be appreciated. Thanks!

2

2 Answers

0
votes

This guide should be able to help you. Although be careful with the first channel the bot can send in, this could be announcements as well.

My recommendation is using a configuration in a database though. This should allow people to set a channel where the message is being sent.

-1
votes

1 way you could do this is to use the discord API to post messages. POST message to channel via discord API

The issue with this is you'll have to know what the channel's ID is.