简体   繁体   中英

Can I move guild member to a voice channel if they aren't in one already?

I am trying to move a member to a voice channel when they type in a certain command in a text channel. I have the functionality working to move a member to different voice channels, but it only works if they are already in a voice channel. I want to be able to move a member to a voice channel even if they are not currently in one. If they are not in any voice channel I get an error. The error is "Target user is not connected to voice."

Unfortunately I haven't found much info online about that error.

bot.on('message', msg => {
  let args = msg.content.substring(prefix.length).split(' ');

  switch (args[0]) {    
    case 'move':
      const members = msg.channel.members.map(member => (member));
      const channel = members[0].guild.channels.find(channel => channel.name === 'test' && channel.type === 'voice');
      members[0].setVoiceChannel(channel.id);
      break;
  }
});

No, you cannot "force" a user to join a voice channel. You never will be able to either because that would be a huge breach of personal security. To have a bot automatically join you to a voice channel could be abused by malicious bots. I'm not saying that your bot is malicious, but others are. It's simply not possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM