我有一个问题:我想检查机器人是否在msg.guild的一个频道上。我有一个命令?checkchannel,它回答机器人是否在上述公会的语音频道上。如果机器人是在一个,它应该回答:“是在一个语音频道”,如果他不是,他应该回答,他不是。
谢谢。
发布于 2021-05-31 11:14:08
很简单,试试这个:
// 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!`);
}注意:
这只检查channel的message,而不是,如果机器人连接到服务器上的any voice channel!
如果您想要检查,如果他已连接到任何 voice channel,您应该查看Viriatos answer
编辑:
您还可以将Vitiaro's answer简化为一行:
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')但你必须自己决定这是否更清楚。
参考文献:
发布于 2021-05-31 11:15:49
如果我理解正确,并且您想要检查机器人是否在中,则公会的语音通道是否与msg.guild相对应。
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');
}https://stackoverflow.com/questions/67771923
复制相似问题