I don't get any errors but when I enter the room my bot doesn't create a new channel

I don't get any errors but when I enter the room my bot doesn't create a new channel

Problem Description:

const Discord = require("discord.js")
const TOKEN = "I WAS WRITE MT TOKEN"


const { Client, GatewayIntentBits } = require('discord.js');
const { MemberFetchNonceLength } = require("discord.js/src/errors/ErrorCodes");

const client = new Discord.Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.DirectMessageTyping,
  ]
})

  client.on("ready", () => {
    console.log(`${client.user.tag} kullanımda`)
  })

  client.on("voiceStateUpdate", async (oldState, newState) => {
    const user = await client.user.fetch(newState.id);
    const member = newState.guild.member(user);

    if (!oldState.channel && newState.channel.id === "I WAS WRITE MY CHANNEL ID"){
        const channel = await newState.guild.channel.create(user.tag, {
            type:"voice",
            parent: newState.channel.parent,
        });
        member.voice.setChannel(channel);
        voiceCollection.set(user.id, channel.id);
    } else if(!newState.channel){
        if(oldState.channelId === voiceCollection.get(newState.id))
        return oldState.channel.delete();
    }
    });

  client.login(TOKEN)

I wanted to make a "Join to create" bot. Actually, the bot works and I don’t get any errors but when I enter the room it doesn’t create a new channel and put me in that channel.

Solution – 1

You’ll need to add the GuildVoiceStates intent to your array:

const client = new Discord.Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.DirectMessageTyping,
    GatewayIntentBits.GuildVoiceStates,
  ]
})

Without that, the voiceStateUpdate event won’t fire.

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject