#Auto Send an embed every hour

59 messages · Page 1 of 1 (latest)

chrome lantern
#

What i want to achieve is that as soon as the bot logs in it will start sending an embed every hour or two hours, but i don't want to run an command to start it this process up i want it to start as soon as the bot starts automatically. Now:

  1. Can you tell me how to achieve that?
  2. Can you please provide me with an code example?

Thanks!

golden lily
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

bold egret
#

I think you can put your "ready" call. for example in nodejs you can do client.on("ready", () => { CODE HERE }) This will execute immediately.

chrome lantern
#

btw Happy New Year!

bold egret
#

and you need it to trigger immediately when the server starts?

#

happy new year to you as well.

chrome lantern
bold egret
#

I'm no expert but I did run into this very recently. I wanted some things to run immediatly and others to run on command

#

immediate execution I put all the code inside the client.on('ready', ...

#

if I want to trigger it manually, like with an call to the server, i'll use the emit

#

I'll show you example of my code that executes immediately

#

and one that executes with emit

bold egret
#

this executes when the server starts

#

and to execute the "ready" commands when you want, like within a specific function, just use the following

#

client.emit("ready");

#

that'll call all ready processes

#

I put that inside an app.get so a certain ready gets called when someone hits a certain address on the server

#

like I said, not my expertise but I'm getting by. Hope it helps

chrome lantern
#

i think my error is in

await interaction.reply({
embeds: [catEmbed],
});```
#

somehwer around interaction thing ig

bold egret
#

This I do not know. I haven't worked with interactions much. Sorry I can't help further. But as I found out the hard way, make sure the docs you are working with are for the correct version number as they are changing often.

chrome lantern
#

Ok thanks!

bold egret
#

np, good luck

cloud plume
chrome lantern
cloud plume
unreal charm
#

This code sends message every 1 hour

client.on('ready',() => {
setInterval(function(){
Your sent message code goes here
}, 3.6e+6)
})
#

@chrome lantern

outer helm
chrome lantern
chrome lantern
#
const channelIds = ['CHANNEL_ID_1', 'CHANNEL_ID_2', ...];

const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);

  // Set the interval for the message to be sent
  setInterval(() => {
    // Iterate over the array of channel IDs
    for (const channelId of channelIds) {
      // Get the channel object from the ID
      const channel = client.channels.cache.get(channelId);
      // Send the message to the channel
      channel.send({
        embed: {
          description: 'Hello World!',
        },
      });
    }
  }, 2 * 60 * 60 * 1000); // 2 hours in milliseconds
});

client.login(token);```
Will this work?
outer helm
cloud plume
#

No, embeds: […] and you need intents in your client constructor

outer helm
#

@chrome lantern don't use for loop in interval because setInterval loop itself

chrome lantern
outer helm
#

Umm ok

chrome lantern
outer helm
#
const channelIds = ['channel-id-1', 'channel-id-2', 'channel-id-3'];
    channelIds.forEach((channelId) => {
      const channel = client.channels.cache.get(channelId);
      channel.send('Hello, world!');
    });
  }, 1000 * 60 * 60); // 1000 milliseconds * 60 seconds * 60 minutes```
chrome lantern
outer helm
# chrome lantern i want to send it as embed not a normal text message
let embed = new MessageEmbed()
.setDescription("Text Here");

const channelIds = ['channel-id-1', 'channel-id-2', 'channel-id-3'];
    channelIds.forEach((channelId) => {
      const channel = client.channels.cache.get(channelId);
      channel.send({
embeds: [embed]
});
    });
  }, 1000 * 60 * 60); // 1000 milliseconds * 60 seconds * 60 minutes```
acoustic wagon
#

however its still api spam

outer helm
chrome lantern
acoustic wagon
chrome lantern
minor treeBOT
#

Ratelimits are dynamically assigned by the API based on current load and may change at any point.
• The scale from okay to API-spam is sliding and depends heavily on the action you are taking
• Rainbow roles, clock and counter channels, and DM'ing advertisements to all members are all examples of things that are not okay

chrome lantern
outer helm
chrome lantern
outer helm
#

Your welcome ☺️

patent minnow
#

I have looked at various references, and after reviewing the topic above, there are some similarities, but my error is different, where .send doesn't work for EmbedBuilder but works if it's just text.

balmy jungle