0

Hey i am trying to write a discord bot to send me notifications in a text channel when someone joins a voice channel, but i keep getting errors..

This is my code

const { Client, Intents } = require('discord.js');
const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_VOICE_STATES
  ]
});

const token = 'MY_TOKEN';
const channelName = 'vc-notifications';

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('voiceStateUpdate', (oldState, newState) => {
  const { member, channel } = newState;
  const textChannel = member.guild.channels.cache.find(channel => channel.name === channelName && channel.type === 'text');

  if (textChannel && channel && channel.type === 'voice') {
    textChannel.send(`${member.user.username} hat den Voice-Chat "${channel.name}" betreten.`);
  }
});

client.login(token);

And this is the Error:

TypeError: Cannot read properties of undefined (reading 'FLAGS')
    at Object.<anonymous> (C:\privat\discord bot\index.js:4:13)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47
Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • If your using v14 take a look at this: https://stackoverflow.com/questions/73040824/discord-js-reads-intents-as-undefined – Samball Mar 28 '23 at 12:29

0 Answers0