【问题标题】:Editing 'Now Playing' embed in Discord Music Bot编辑嵌入 Discord Music Bot 的“正在播放”
【发布时间】:2021-06-26 21:22:30
【问题描述】:

我想将此嵌入编辑到滑块“????”的位置每 7 秒移动一次。我还希望“剩余时间:”每 7 秒更改一次。

目前所有的变化是“queue.formattedCurrentTime”和“song.formattedDuration”

这是我到目前为止的代码。有什么建议吗?

const { MessageEmbed } = require('discord.js-light')
const createBar = require('string-progressbar')
const { toColonNotation } = require('colon-notation')
module.exports = {
    name: 'np',
    aliases: ['nowplaying', 'currentsong'],
    description: 'Show the currently playing song.',
    usage: `${prefix}np`,
    run: async(bot, message) => {
        const queue = bot.distube.getQueue(message)
        if(!queue) return message.channel.send('There are no songs in the queue.')
        if(!queue && !bot.distube.isPlaying(message)) return('There is nothing playing.')
        const song = queue.songs[0]
        const name = song.name
        const user = song.user.tag
        const avatar = song.user.displayAvatarURL({ dynamic: true, format: "png" })
        const link = song.url
        const time = song.duration * 1000
        const currenttime = queue.currentTime
        const tn = song.thumbnail
        const remaining = (time - currenttime < 0 ? "◉ LIVE" : time - currenttime)
        try {
            const embed = new MessageEmbed()
            .setTitle(name)
            .setAuthor(user, avatar)
            .setURL(link)
            .setDescription(`${createBar(time === 0 ? currenttime: time, currenttime, 27, "─", "????")[0]} \`[${queue.formattedCurrentTime}/${song.formattedDuration}]\`\n` +
            `${bot.distube.isPaused(message) === true ? "⏸" : "▶"} ${time === 0 ? "" : `| **Time Remaining:**\`${toColonNotation(remaining)}\``}`)
            .addField('In Channel:',  `**${message.member.voice.channel.name}**`, { inline: true })
            .addField('From Playlist:', song.fromPlaylist ? "✅" : "❌", { inline: true })
            .setColor('#c1abff')
            .setThumbnail(`${tn}`)
            message.channel.send(embed).then((message) => {
                var countdown = 10;
                const interval = setInterval(() => {
                    if (countdown < 0) clearInterval(interval);
                    const embed = new MessageEmbed()
                    .setTitle(name)
                    .setAuthor(user, avatar)
                    .setURL(link)
                    .setDescription(`${createBar(time === 0 ? currenttime: time, currenttime, 27, "─", "????")[0]} \`[${queue.formattedCurrentTime}/${song.formattedDuration}]\`\n` +
                    `${bot.distube.isPaused(message) === true ? "⏸" : "▶"} ${time === 1 ? "" : `| **Time Remaining:**\`` + new Date()`${toColonNotation(remaining)}\``}`)
                    .addField('In Channel:',  `**${message.member.voice.channel.name}**`, { inline: true })
                    .addField('From Playlist:', song.fromPlaylist ? "✅" : "❌", { inline: true })
                    .setColor('#c1abff')
                    .setThumbnail(`${tn}`)
                    message.edit(embed)
                }, 7000)
            })
        } catch (e) {
            message.channel.send(`There was an issue: \n\`${e}\``)
        }
    }
}

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    不断更新嵌入可能不是解决此问题的理想方式。

    相反,您可以尝试我在“正在播放”命令中的内容,并在您的嵌入中使用“时尚文本”。

    const bar = require(`stylish-text`)
    
        function toReadableTime(given){
            var time = given;
            var minutes = "0" + Math.floor(time / 60);
            var seconds = "0" + (time - minutes * 60);
            return minutes.substr(-2) + ":" + seconds.substr(-2);
        }
    
        const current = Math.floor(serverQueue.connection.dispatcher.streamTime / 1000) //ms --> seconds
        const end = serverQueue.songs[0].length //video in seconds
        
        const value = (current * (100 / end) / 5)
        
        bar.default.full = "█";
        bar.default.empty = " - ";
        bar.default.start = "";
        bar.default.end = "";
        bar.default.text = "{bar}";
    
    `${toReadableTime(current)} - [${bar.progress(20, value)}] - ${toReadableTime(end)}` //This would go in your embed
    

    输出:

    【讨论】:

      猜你喜欢
      • 2021-02-03
      • 2020-09-19
      • 2021-01-21
      • 1970-01-01
      • 2020-08-02
      • 2021-03-23
      • 2021-11-07
      • 2021-08-12
      • 2019-02-27
      相关资源
      最近更新 更多