Skip to content
Advertisement

how can i move users with reaction

im trying to create bot that move users when they react in message create channel and move the user to the channel that was created , err = Cannot read property 'setChannel' of undefined

if(reaction.message.id == ticketid && reaction.emoji.name == '🔊') {
 reaction.users.remove(user);


if(reaction.message.guild.channels.cache.find(channel => channel.name === `🔊 | ${user.username}`)) {
            return user.send('> ❕ | *you already **have** a channel*.!');
        }


           catagore = reaction.message.guild.channels.cache.find(channel => channel.name === "🔊 | react to create")
         
 const createdChannel = await reaction.message.guild.channels.create(`🔊 | ${user.username}`, {
      
  type: 'voice',
  parent: catagore.id,

 
 
        })
console.log(createdChannel.id)
const { id } = createdChannel;
  
const mem = user.id
  
 mem.voice.setChannel(createdChannel.id)
    
      .then(() => console.log(`Moved ${mem.displayName} to ${createdChannel}`))
  .catch(console.error);

Advertisement

Answer

You need a GuildMember to access their voice state. Your mem variable is wrong so, you need to get the member instead.

reaction.message.guild.members.fetch(user.id).then(member => {
  member.voice.setChannel(createdChannel.id).then(() =>
    console.log(`Moved ${mem.displayName} to ${createdChannel}`))
  .catch(console.error);
});
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement