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
JavaScript
โx
29
29
1
if(reaction.message.id == ticketid && reaction.emoji.name == '๐') {
2
reaction.users.remove(user);
3
โ
4
โ
5
if(reaction.message.guild.channels.cache.find(channel => channel.name === `๐ | ${user.username}`)) {
6
return user.send('> โ | *you already **have** a channel*.!');
7
}
8
โ
9
โ
10
catagore = reaction.message.guild.channels.cache.find(channel => channel.name === "๐ | react to create")
11
12
const createdChannel = await reaction.message.guild.channels.create(`๐ | ${user.username}`, {
13
14
type: 'voice',
15
parent: catagore.id,
16
โ
17
18
19
})
20
console.log(createdChannel.id)
21
const { id } = createdChannel;
22
23
const mem = user.id
24
25
mem.voice.setChannel(createdChannel.id)
26
27
.then(() => console.log(`Moved ${mem.displayName} to ${createdChannel}`))
28
.catch(console.error);
29
โ
JavaScript
1
1
1
โ
Advertisement
Answer
You need a GuildMember to access their voice state.
Your mem
variable is wrong so, you need to get the member instead.
JavaScript
1
6
1
reaction.message.guild.members.fetch(user.id).then(member => {
2
member.voice.setChannel(createdChannel.id).then(() =>
3
console.log(`Moved ${mem.displayName} to ${createdChannel}`))
4
.catch(console.error);
5
});
6
โ