Home > OS >  embed update - slash command
embed update - slash command

Time:12-11

I have the following code that creates a slash command. I want the embed to be updated every 10 seconds.

const embed = new EmbedBuilder()
    .setAuthor({ name: track.title, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
    .setThumbnail(track.thumbnail)
    .addFields(
        { name: "**volume**", value: `**${queue.volume}**` },
        { name: "**اtime**", value: `**${trackDuration}**` },
        { name: "**song**", value: `**${progress}**` },
        { name: "**repeat mode**", value: `**${methods[queue.repeatMode]}**` },
        { name: "**track**", value: `**${track.requestedBy}**` }
    )
    .setFooter({ text: inter.user.username, iconURL: inter.member.avatarURL({ dynamic: true }) })
    .setColor("ff0000")
    .setTimestamp();

I tried with setInterval but it didn't work.

CodePudding user response:

You really need to add more information, but you could use setInterval().

I am just taking a guess on how you use your bot, interaction.editReply() is my guess that you send the embed as a reply, but you can change it to whatever you want, and the code within the setInterval will run once every 10 seconds.

EDIT: You also need to send the initial reply if you wish to edit it.

e.g.

const embed = new EmbedBuilder()
  .setAuthor({ name: track.title, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
  .setThumbnail(track.thumbnail)
  .addFields(
    { name: '**volume**', value: `**${queue.volume}**` },
    { name: '**اtime**', value: `**${trackDuration}**` },
    { name: '**song**', value: `**${progress}**` },
    { name: '**repeat mode**', value: `**${methods[queue.repeatMode]}**` },
    { name: '**track**', value: `**${track.requestedBy}**` }
  )
  .setFooter({ text: inter.user.username, iconURL: inter.member.avatarURL({ dynamic: true }) })
  .setColor('ff0000')
  .setTimestamp();
// You need to send the initial embed if you wish to edit it
interaction.reply({ embeds: [embed] });

setInterval(() => {
  // Code to run every 10 seconds:
  interaction.editReply({ embeds: [embed] });
  // 10 seconds in milliseconds
}, 10000);
  • Related