Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'client' of undefined #8

Closed
JamesGW-iOS opened this issue Aug 12, 2019 · 74 comments
Closed

TypeError: Cannot read property 'client' of undefined #8

JamesGW-iOS opened this issue Aug 12, 2019 · 74 comments
Assignees
Labels
not-code-issue User-end issue rather than code issue

Comments

@JamesGW-iOS
Copy link

When I try the play command, always after I say the name of the song it says in chat that something went wrong with the search of said song and then when I look in the console it says
"TypeError: Cannot read property 'client' of undefined
at new MessageEmbed
\node_modules\discord.js\src\structures\MessageEmbed.js:10:60)
at PlayCommand.run
\commands\music\play.js:144:21)
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at async CommandMessage.run
\node_modules\discord.js-commando\src\commands\message.js:212:19)
at async CommandDispatcher.handleMessage
\node_modules\discord.js-commando\src\dispatcher.js:127:19)
events.js:194"
Btw I took out where it says my name as a user like C:\Users\NAME\Docs\NAME.OF.FOLDER\ANOTHER.NAME

@galnir galnir self-assigned this Aug 12, 2019
@galnir
Copy link
Owner

galnir commented Aug 12, 2019

I've never seen this error so I researched a bit, this is not a code error.
There are many reasons this can happen, try these solutions:

  1. Have you changed the owner id in index.js line 7 to your Discord user id?

  2. Some guy got this exact error because he didn't have Git installed, as a result he installed the stable version of Commando which uses RichEmbed not MessageEmbed. So go ahead and run npm install discordjs/Commando in your terminal. If an error pops up, you don't have Git installed and that's the problem.

@CaptainYannick
Copy link

I've had the same issue tried both of your solutions but now I've got this error https://sourceb.in/7bf522532c are you able to help me?

@galnir
Copy link
Owner

galnir commented Aug 14, 2019

@CaptainYannick Have you installed Commando and discord.js v12 correctly?
When running npm view discord.js version you should get 11.5.1
and you should get 0.10.0 from running npm view discord.js-commando version

@CaptainYannick
Copy link

@galnir Yes I have those versions

@CaptainYannick
Copy link

@galnir I fixed it forgot to install discord.js master

@galnir
Copy link
Owner

galnir commented Aug 15, 2019

@JamesGW-iOS What about you?

@galnir galnir added the not-code-issue User-end issue rather than code issue label Aug 17, 2019
@Beastskyler
Copy link

I am also having the same error as @CaptainYannick but no matter how many times I try to install discord.js master, I still get the same error.

@galnir
Copy link
Owner

galnir commented Sep 21, 2019

@Beastskyler Did you install Commando correctly?
Run npm view discord.js-commando version

@Beastskyler
Copy link

npm view discord.js-commando version

I got version 0.10.0. Also, if I uninstall both discord.js and commando, I can get my bot run but then if I run the play command, I get TypeError: Cannot read property 'client' of undefined. So I reinstall both discord.js and commando.js and I get TypeError: Cannot read property 'extend' of undefined.

@galnir
Copy link
Owner

galnir commented Sep 21, 2019

@Beastskyler Did you clone the repo or did you copy the music commands?

@Beastskyler
Copy link

Copy

@Beastskyler
Copy link

Your command is the only good one I could find that would go with my bot.

@galnir
Copy link
Owner

galnir commented Sep 21, 2019

So you probably didn't create an instance of CommandoClient in your index.js if you didn't use Commando before. Take a look at my index.js file

@galnir
Copy link
Owner

galnir commented Sep 21, 2019

Commando is a framework, so if you wish to use it you need to register command groups and stuff like that. Take a look at its docs

I recommend you to use it, makes writing commands wayy easier

@Beastskyler
Copy link

Beastskyler commented Sep 21, 2019

This is what I have in my Index.js, I have my token in I it becasue every time I try to use a config.json, I can never get it to work.

https://hastebin.com/sibokeceqo.php

@Beastskyler
Copy link

I have used commando for all of my commands

@galnir
Copy link
Owner

galnir commented Sep 21, 2019

Add me on discord - hyperzone#1185
I'll try to solve your problem on dms and when we solve it I'll comment the solution here

@galnir
Copy link
Owner

galnir commented Sep 21, 2019

Beastskyler's issue was a var naming issue

@galnir
Copy link
Owner

galnir commented Oct 19, 2019

Will reopen if you still have this

@galnir galnir closed this as completed Oct 19, 2019
@painownage1
Copy link

still got this

@galnir
Copy link
Owner

galnir commented May 22, 2020

@painownage1 got what? Did you install the dependencies correctly?

@Lunyyx
Copy link

Lunyyx commented Jun 4, 2020

Personnaly, I have this error:
TypeError: Cannot read property 'client' of undefined at new MessageEmbed (/root/bot/node_modules/discord.js/src/structures/MessageEmbed.js:13:60) at command (/root/bot/commands/utilities/blocks-convert.js:7:19) at Client.event (/root/bot/events/message.js:11:133) at Client.emit (events.js:315:20) at MessageCreateHandler.handle (/root/bot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34) at WebSocketPacketManager.handle (/root/bot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65) at WebSocketConnection.onPacket (/root/bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35) at WebSocketConnection.onMessage (/root/bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17) at WebSocket.onMessage (/root/bot/node_modules/ws/lib/event-target.js:120:16) at WebSocket.emit (events.js:315:20)
It's similar

@galnir
Copy link
Owner

galnir commented Jun 5, 2020

@Luunyx Then you didn't install discordjs or Commando correctly, did you clone this repo or copy code?

@Lunyyx
Copy link

Lunyyx commented Jun 5, 2020

@Luunyx Then you didn't install discordjs or Commando correctly, did you clone this repo or copy code?

No I fully use my own bot, I not copied this

@galnir
Copy link
Owner

galnir commented Jun 5, 2020

@Luunyx You probably have discordjs v11 installed and not v12. What do you mean use my own bot? Did you even clone this repo? If you did, all you need to do is follow the instructions and it will work

@NiNj4HAX
Copy link

NiNj4HAX commented Jul 6, 2020

TypeError: Cannot read property 'client' of undefined
at new MessageEmbed (C:\Windows.old\Users\tukin\Desktop\BOT\Kaz#0001\node_modules\discord.js\src\structures\MessageEmbed.js:13:60)
at Object. (C:\Windows.old\Users\tukin\Desktop\BOT\Kaz#0001\index.js:5:15)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47

@NemSeih
Copy link

NemSeih commented Jul 23, 2020

I resolved this error updating my NPM and my Discord.JS.

Try it in your terminal:
npm install -g npm
npm install discord.js

it may take between 5 and 15 minutes

@anish-kum
Copy link

Also, I downloaded something called cheerio and request packages if that has anything to do with it.

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

That is really weird.
To check the vers, do it in your terminal:
npm view discord.js version

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

Also, I downloaded something called cheerio and request packages if that has anything to do with it.

what do it do? (cheerio)

@anish-kum
Copy link

anish-kum commented Jan 7, 2021

OH MY GOD. I HAVE VERSION 15.5

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

really?
that is REALLY weird

@anish-kum
Copy link

When I do node -v. It says v15.5.0

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

oh, its node's version

Do it:
npm view discord.js version

@anish-kum
Copy link

Now it says ncaught TypeError: (intermediate value).setColor(...).setTitle(...).addFields is not a function when I do !command which is an embed

@anish-kum
Copy link

Version 12.5.1 I checked now. Look at the message above though.

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

i really do no what is it

i'm testing in my pc, I already answer here

@anish-kum
Copy link

So what now?

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

wait pls

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

Screenshot_1
🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔

@anish-kum
Copy link

How though?

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

I used const embed = new Discord.MessageEmbed(), and it works fine

@anish-kum
Copy link

Not for me sadly

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

image

yeah it works fine

@anish-kum
Copy link

Not for me though. Its sad because I put a lot of effort and it does not work.

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

image

I used v12.5.1 with this code:

const Discord = require('discord.js');
const bot = new Discord.Client();
const PREFIX = '!';
const RED_ROLE = '795365856288702475';
const BLUE_ROLE = '795365944724553768';
var version = '1.01';

bot.on('ready', () => {
console.log('The bot is ready.');
bot.user.setActivity("Type !command. HATCHING RIOLU LIKE A BOSS")

});

if (bot.on) {

bot.on('message', msg=>{
if (msg.content === "!Joke") {
msg.channel.send("Q: Whats the best book? A: The chromebook!")

}

});
bot.on('message', msg=>{
if (msg.content === "!Welcome Message") {
msg.reply("Welcome to #general chat! Chat with anyone, but make sure to follow the guidlines MEE6 listed! For further use of bot, please type in !command for commands for the robot, and for further questions don't hesitate at all to DM @SPZ_Zapper!!")
msg.reply(:grinning: )

}

});

bot.on('message', message=> {
if (message.content === '!smileyface') {
message.channel.send(:grinning: )

  }

});

}
bot.on('message', message=> {

let args = message.content.substring(PREFIX.length).split(" ");

switch(args[0]) {
case 'userinfo':
const embed = new Discord.MessageEmbed()
.setTitle('User Information')
.addField('User name', message.author.username)
.addField('User ID. Note... will not harm your account if others see it.', message.author.id)
.addField('Version', version)
.addField('Current Server', message.guild.name)
.addField('Date joined', message.guild.joinedAt)
.addField('Account created', message.author.createdAt)
.setThumbnail(message.author.displayAvatarURL())
.setColor(0xF1C40F)
.setThumbnail(message.author.avatar)

  message.channel.send(embed);
break;

}

});
bot.on('message', message=> {

let args = message.content.substring(PREFIX.length).split(" ");

switch(args[0]) {
case 'command':
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Commands for Lucario Bot!!!')
.addFields(
{name: 'This is a way to access Lucarios commands!', value: 'Note that these commands will either be updated, or new commands will be added. These commands are case sensitive!!'},
{name: '!userinfo', value: 'Type !userinfo in for a quick summary of yourself. Note that you can only see yourself, but not others.'},
{name: '!Joke', value: 'Type !Joke in for the bot to give you a joke! There is only one so far, but will keep on updating!!'},
{name: '!Welcome Message', value: 'Type in !Welcome Message for a nice warm welcome from the Lucario bot!!'},
{name: '!jointeam', value: 'Type this in to see the exclsuive roles you can get for this server. Join one team,'},
{name: '!lucariobio', value: 'Type this in to see the story of the developement of the bot!!'},
{name: '!poll', value: 'Type this in, there will then be a new embed for further instructions.'},
)
message.channel.send(embed);

}

});
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");

switch(args[0]) {
case 'lucariobio':
const embed = new Discord.MessageEmbed()
.setTitle('Bio on Lucario bot, and how it was developed.')
.addFields(
{name: 'Bio of LUCARIO BOT!!', value: 'The Lucario bot was fully developed by (Dont want to show name) Fully developed in Javascript with an abundance of commands. You can always help with the developent of the bot.'},
)
message.channel.send(embed);

}

});
bot.on('message', message=> {

let args = message.content.substring(PREFIX.length).split(" ");

switch(args[0]) {
case 'jointeam':
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Teams to join. Pick wisely, once you pick, this is the permenant team you will be on. Contact @SPZ_Zapper is you want to change. Once you get the role you will unlock a chat. Remember to only pick one role, and you will unlock one chat.')
.addFields(
{name: '+RED_ROLE', value: 'Type this in to get the exclusive Red Role Groudon role. To see roles click on your self when you chat.'},
{name: '+BLUE_ROLE', value: 'Type this in to get the exclusive Blue Role Kyogre role. To see the roles click on your self when you chat. '},
)
message.channel.send(embed);

}
});
bot.on('message', message=> {
let args = message.content.substring(PREFIX.length).split(" ");

switch(args[0]) {
case 'poll':
const Embed = new Discord.MessageEmbed()
.setColor(0xffc300)
.setTitle('Initiate Poll')
.setDescription('This is how you can initiate any poll. You first type in !poll then space, then the question you want. Here is an example !poll Are cats better than Dogs?')

  if(!args[1]) {
    message.channel.send(Embed)
    break;
  }

  let msgArgs = args.slice(1).join(" ");

  message.channel.send( "📖" + "**" + msgArgs + "**").then(messageReaction => {
    messageReaction.react('✅');
    messageReaction.react('❌');
    

  });
  
break;

}

});
bot.on('message', (message) => {

if (message.content === '+RED_ROLE') {
message.member.roles.add(RED_ROLE)
message.reply('Red role successfully added!')
message.react('👍')
if (message.reactions = :thumbsup) {
message.reply('ha')
}

}

if (message.content === '+BLUE_ROLE') {
message.member.roles.add(BLUE_ROLE)
message.reply('Blue role successfully added!')
message.react('👍')

}

});
bot.login(token);

@anish-kum
Copy link

It worked yesterday very well.

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

did you use a VPS or any server?

@anish-kum
Copy link

what do you mean?

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

The BOT is running in your PC (cmd, Visual Studio Code Terminal) or its in a server (Virtual Private Server [VPS])

@anish-kum
Copy link

Visual Studio Code terminal

@NemSeih
Copy link

NemSeih commented Jan 7, 2021

I really dont know what is this bug... I'm sorry :/
I used the code with Discord.MessageEmbed(), in discord.js v12.5.1 and it works fine.

@anish-kum
Copy link

Ok. I guess

@anish-kum
Copy link

Really sad about this.

@anish-kum
Copy link

@NemSeih? Now its just saying Uncaught TypeError: (intermediate value).setColor(...).setTitle(...).addFields is not a function for !command, !jointeam, etc?

@galnir
Copy link
Owner

galnir commented Jan 7, 2021

@anish-kum The code you're posting here isn't from this repository, you can't get help unless you use the code here without modifying it too much

@anish-kum
Copy link

Ok. sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-code-issue User-end issue rather than code issue
Projects
None yet
Development

No branches or pull requests

9 participants