首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编辑嵌入不一致音乐机器人中的“Now Playing”

编辑嵌入不一致音乐机器人中的“Now Playing”
EN

Stack Overflow用户
提问于 2021-03-31 04:31:15
回答 1查看 687关注 0票数 4

我想编辑这个嵌入到滑块"?“每7秒移动一次的地方。我还希望“剩余时间:”每7秒更改一次。

现在,所有的变化都是"queue.formattedCurrentTime“和"song.formattedDuration”

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

代码语言:javascript
复制
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}\``)
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2021-06-10 01:48:13

不断更新embed可能不是一个理想的解决方案。

相反,你可以尝试我在“现在播放”命令中的方法,并在你的嵌入中使用“Stylish text”。

代码语言:javascript
复制
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

输出:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66878067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档