discord.js 中的音量命令
Volume command in discord.js
我已经发出命令并且它有效但它不会改变机器人的音量它一直说“音量只能设置在 `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}**`)
不就是给args
赋值的时候少了.split()
吗?
const args = message.content.split(" ");
它将消息内容按空格分解成一个数组。您的命令将如下所示 "volume 5
.
我已经发出命令并且它有效但它不会改变机器人的音量它一直说“音量只能设置在 `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}**`)
不就是给args
赋值的时候少了.split()
吗?
const args = message.content.split(" ");
它将消息内容按空格分解成一个数组。您的命令将如下所示 "volume 5
.