【发布时间】:2020-12-08 07:33:56
【问题描述】:
我正在尝试为我的机器人发出离开命令并且我正在尝试这样做,因此如果使用该命令的人与机器人不在同一个语音频道中,它会响应并告诉他们必须使用相同的声音频道,如果他们在,它将离开
到目前为止我有这个,但我不知道如何只获取机器人和用户所在频道的 ID 以比较它们
let userVoiceChannel = message.member.voice.connection;
let crashbotVoiceChannel = Crashbot.voice.connections;
返回机器人和用户所在频道的所有信息
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;
}
});
【问题讨论】:
标签: javascript discord discord.js