// If the bot is not connected to a voice channel, the 'channel' object should be 'undefined'
if(msg.guild.voice.cannel)
{
msg.channel.send(`I'm in a voice channel!`);
}
else
{
console.log(`I'm not in a voice channel!`);
}
msg.guild.channels.cache.some(channel => (channel.type === 'voice' && channel.members.has(Client.user.id)) ? msg.channel.send('It is on a voice channel') : msg.channel.send('It is not on a voice channel')
if(msg.guild.channels.cache.some(channel => (channel.type === 'voice' && channel.members.has(Client.user.id)) {
msg.channel.send('It is on a voice channel'); // Replies on the same channel the command was sent to
}
else {
msg.channel.send('It is not on a voice channel');
}
3条答案
按热度按时间8ulbf1ek1#
很简单,试试这个:
注:
这只检查
message
的channel
,而不是如果bot连接到服务器上的任何voice channel
!如果您要检查,如果他连接到任何
voice channel
,您应该检查Viriatos answer编辑:
您还可以将Vitiaro's answer缩减为一行:
但你必须自己决定这是否更清楚。
参考文献:
guild#voice#channel
swvgeqrz2#
如果我没理解错的话,你想查看bot是否在
msg.guild
对应的公会的任意语音通道中:guykilcj3#
以下是最新discord.js版本(v14)的解决方案