So I am trying to make some changes in this discord bot script.But to be honest I don't know anything about javascript.So this is the error I am getting.
Error:
client = new Client();
ReferenceError: Client is not defined
And here this is my code:
require('discord.js'),
client = new Discord.Client();
client.once('ready',
() => console.info('Bot started.')
);
client.on('voiceStateUpdate', (Old, New) => {
if(New.user.bot) return;
if(Old.user.bot) return;
if(New.voiceChannelID == process.env.voiceID) {
New.guild.createChannel(New.user.username, { type: "voice", parent: process.env.categoryID })
.then((set) => {
return New.setVoiceChannel(New.guild.channels.get(set.id));
});
}
if(Old.voiceChannel) {
let filter = (ch) =>
(ch.parentID == process.env.categoryID)
&& (ch.id !== process.env.voiceID)
&& (Old.voiceChannelID == ch.id)
&& (Old.voiceChannel.members.size == 0);
return Old.guild.channels
.filter(filter)
.forEach((ch) => ch.delete());
}
});
client.login(process.env.BOT_TOKEN);```
CodePudding user response:
You didn't define Discord
, so when you call new Discord.Client()
you get the error.
In the first line of your code replace require('discord.js')
with:
const Discord = require('discord.js')
You also need to actually define your client
, in your second line add the const keyword:
const client = new Discord.Client();
CodePudding user response:
You are supposed to declare Discord
const Discord=require('discord.js');
const client = new Discord.Client();
CodePudding user response:
NodeJS use CommonJS modules as documented here.
Get one of the Discord.js exported modules:
const { Client } = require('discord.js'); // Client
Get the entire Discord.js module:
const Discord = require('discord.js'); // Discord.Client
CodePudding user response:
You need to define your client..
all you gotta do is at the top add this script:
const { client } = new Discord.Client();