【问题标题】:Volume command in discord.jsdiscord.js 中的音量命令
【发布时间】:2021-09-21 19:09:11
【问题描述】:

我已经发出命令并且它可以工作,但它不会改变机器人的音量它一直说“音量只能设置在 `1` - `100 的范围内`" 但我输入了“第 1 卷,但它不起作用

命令 -

 } else if (message.content.startsWith('"volume')) {
        const args = message.content
        if (!message.member.voice.channel) return message.channel.send("I'm sorry, but you need to be in a voice channel to set a volume!");
        if (!serverQueue) return message.channel.send("There is nothing playing");
        if (!args[1]) return message.channel.send(`The current volume is: **\`${!serverQueue.volume}%\`**`);
        if (isNaN(args[1]) || args[1] > 100) return message.channel.send("Volume only can be set in a range of **\`1\`** - **\`100\`**");
        serverQueue.volume = args[1];
        serverQueue.connection.dispatcher.setVolume(args[1] / 100);
        return message.channel.send(`I set the volume to: **\`${args[1]}%\`**`);
        return;

函数-

 const dispatcher = serverQueue.connection
        .play(ytdl(song.url))
        .on("finish", () => {
            if (!serverQueue.loop) serverQueue.songs.shift()
            play(guild, serverQueue.songs[0]);
        })
        .on("error", error => console.error(error));
    dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
    serverQueue.textChannel.send(`Started playing: **${song.title}**`)

【问题讨论】:

    标签: discord discord.js command volume


    【解决方案1】:

    是不是因为分配给args时缺少.split()

    const args = message.content.split(" ");
    

    它将消息内容按空格分隔成一个数组。你的命令看起来像这样"volume 5

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      • 1970-01-01
      • 2021-12-04
      • 2021-02-07
      • 2021-08-09
      • 2021-07-10
      • 2021-06-08
      相关资源
      最近更新 更多