Micro Explorer
Micro Explorer

Reputation: 29

Doesn't create the voice channel with no error

I am trying to build a bot with the discord.js library in node.js that will create a new voice channel in a certain category when a user joins a certain channel. After the creation of the channel, I want the bot to then move the user to the new channel!

I am trying the following code:

var temporary = [];

client.on('voiceStateUpdate', async (oldMember, newMember) => {
 const mainCatagory = '815281015207624704';
 const mainChannel = '814938402137833484';

 if (newMember.voiceChannelID == mainChannel) {
  await newMember.guild
   .createChannel(`📞 ┋ Support Room`, { type: 'voice', parent: mainCatagory })
   .then(async (channel) => {
    temporary.push({ newID: channel.id, guild: newMember.guild.id });
    await newMember.setVoiceChannel(channel.id);
   });
 }

 if (temporary.length >= 0)
  for (let i = 0; i < temporary.length; i++) {
   let ch = client.guilds
    .find((x) => x.id === temporary[i].guild)
    .channels.find((x) => x.id === temporary[i].newID);

   if (ch.members.size <= 0) {
    await ch.delete();

    return temporary.splice(i, 1);
   }
  }
});

The code comes with no error but doesn't create the voice channel!

Upvotes: 0

Views: 292

Answers (1)

Lioness100
Lioness100

Reputation: 8402

The problem is that you are using discord.js v12, but your code is made for v11.

(As a side note, always use Collection#get instead of Collection#find when searching by IDs. .find((value) => value.id === '...') should always be converted to simply .get('...'). This also applies to switching Collection#some with Collection#has)

Every single one of these deprecations occurred as a result of discord.js switching to a Manager/caching system. For example, Client#guilds now returns a GuildManager instead of a collection.

More information about switching from v11 to v12 (including Managers)

Upvotes: 1

Related Questions