亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

更新 Discord Music Bot 中嵌入的“正在播放”

更新 Discord Music Bot 中嵌入的“正在播放”

拉莫斯之舞 2023-05-25 15:37:44
我正在制作一個主要功能是播放音樂的不和諧機器人。我有一個正在播放的命令,它會顯示您在歌曲中的進度,我想每 5 秒左右進行一次更新。我知道編輯嵌入,但我需要它一直循環直到歌曲停止。這是現在的代碼:const createBar = require("string-progressbar");const { MessageEmbed } = require("discord.js");module.exports = {  name: "np",  description: "Show now playing song",  execute(message) {    const queue = message.client.queue.get(message.guild.id);    if (!queue) return message.reply(`Nothing's playing right now!`).catch(console.error);    const song = queue.songs[0];    const seek = (queue.connection.dispatcher.streamTime - queue.connection.dispatcher.pausedTime) / 1000;    const left = song.duration - seek;    let nowPlaying = new MessageEmbed()      .setTitle("Now playing:")      .setDescription(`${song.title}\n\`Requested by:\` ${message.author}`)      .setColor("#ff0000")      .setThumbnail('https://img.icons8.com/clouds/2x/play.png')      .addField(        "\u200b",        new Date(seek * 1000).toISOString().substr(11, 8) +          "[ " +          createBar(song.duration == 0 ? seek : song.duration, seek, 10)[0] +          "] " +          (song.duration == 0 ? " ? LIVE" : new Date(song.duration * 1000).toISOString().substr(11, 8)),        false      );    if (song.duration > 0)      nowPlaying.setFooter("Time Remaining: " + new Date(left * 1000).toISOString().substr(11, 8));    return message.channel.send(nowPlaying);  }};
查看完整描述

1 回答

?
皈依舞

TA貢獻1851條經驗 獲得超3個贊

您可以使用 定期編輯嵌入setInterval(),然后使用 停止編輯(一旦歌曲完成)clearInterval()。他們是這樣工作的:

var countdown = 10;


// this is fine, except it doesn't stop at 0

setInterval(() => console.log(countdown--), 1000);


// we can use `clearInterval()` to stop the interval once it gets to 0

var countdown = 10;


const interval = setInterval(() => {

?console.log(countdown--);

?if (countdown < 0) clearInterval(interval);

}, 1000);



查看完整回答
反對 回復 2023-05-25
  • 1 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號