我试图为我的机器人发出请假命令,然后我试图这样做,所以如果使用该命令的人与机器人不在同一个语音通道中,它将响应并告诉他们必须使用相同的声音频道,如果有,它将离开
到目前为止,我已经掌握了这个,但是我无法弄清楚如何获取机器人和用户要比较的频道的ID
let userVoiceChannel = message.member.voice.connection;
let crashbotVoiceChannel = Crashbot.voice.connections;
返回有关机器人和用户所在频道的所有信息,我只是想不出如何挑选ID来比较这些ID
Crashbot.on('message', async message =>{
//creates an array called args and removes the first amount of charactors equal to the length of the prefix variable
let args = message.content.substring(PREFIX.length).split(" ");
let userVoiceChannel = message.member.voice.connection;
let crashbotVoiceChannel = Crashbot.voice.connections;
console.log(userVoiceChannel[0])
console.log(crashbotVoiceChannel)
//the switch equals true if the first word after the prefix is "leave"
switch (args[0]) {
case 'leave':
if (userVoiceChannel === null) return; message.reply("You must be a voice channel to use this command");
//if the message author is not in the same voice channel as the bot the bot replies and tells them that that have to be in the same channel to use that command
if (userVoiceChannel !== crashbotVoiceChannel) {
message.reply("You must be in the same channel as me to use this command");
return;
}
//if the message author is in the same voice channel as the bot it leaves the channel it is in
else if (userVoiceChannel === crashbotVoiceChannel) {
const connection = await message.member.voice.channel.leave();
message.channel.send("Successfully left the voice channel");
}
break;
}
});
答案 0 :(得分:1)
Client.voice.connections
返回的Collection
与您的漫游器在所有行会之间的所有语音连接一样。
您必须获得当前公会的连接。您可以使用:
message.guild.me.voice
// Getting the author's voice connection.
const userVoiceChannel = message.member.voice;
// Getting the bot's voice connection.
const botVoiceChannel = message.guild.me.voice;
// Checking if the bot is in a voice channel.
if (!botVoiceChannel.channel) return message.reply("The bot is not in a voice channel.");
// Checking if the member is in a voice channel.
if (!userVoiceChannel.channel) return message.reply("You need to be in a voice channel.");
// Checking if the member is in the same voice channel as the bot.
if (botVoiceChannel.channelID !== userVoiceChannel.channelID) return message.reply("You need to be in the same channel as the bot.");
message.reply("Everything works.");