Cannot read property 'name' of undefined discord.js - node.js

I have an error with the help command, the error is
<rejected> TypeError: Cannot read property 'name' of undefined
at /home/runner/mUdollar1cB0t/commands/help.js:16:55
client.commands.forEach(cmd => {
let cmdinfo = cmd.info
allcmds+="`" + client.config.prefix + cmdinfo.name+" " + cmdinfo.usage+"` ~ " + cmdinfo.description+"\n"
})
is the code I don't know what's wrong.

In your code, cmdinfo is undefined, you need to verify if you have some data in cmd.info to proceed with your code.

Related

TypeError: Cannot read property 'Grid' of undefined thrown in Table.forceUpdateGrid

I am attempting to call tableInstance.forceUpdateGrid() inside a Promise.then() callback and it is throwing an exception TypeError: Cannot read property 'Grid' of undefined
Looking at the following code
_createClass(Table, [{
key: 'forceUpdateGrid',
value: function forceUpdateGrid() {
this.Grid.forceUpdate();
}
the this reference is undefined...
the only thing I can think of is that in-between the initial BE api call and the Promise.then() handler, there has been a props change that has caused the containing component to re-render and maybe the tableInstance reference no longer points to the correct instance?
Can anyone help?
(1) Use fat arrow functions to get this reference inside function :-
_createClass(Table, [{
key: 'forceUpdateGrid',
value: forceUpdateGrid = () => {
this.Grid.forceUpdate();
}
(2)Or,
let thisRef = this;
_createClass(Table, [{
key: 'forceUpdateGrid',
value: function forceUpdateGrid() {
thisRef.Grid.forceUpdate();
}
i hope it helps!

TypeError: Cannot read property 'AccountToken' of undefined

Trying to run the following test for a select component that is being import 'react-select'
I have the click events running fine, but onChange event is displaying an error:
TypeError: Cannot read property 'Accounts' of undefined
Here is where the error is located, line :
setReport = () => {
let data = this.state.Account.accountBody;
this.setState({
AccountToken: data.AccountToken,
Render();
<Select
className={'field-input-select margin-right'}
id='accounts-id-test'
value={this.state.Account}
onChange={(e) => { this.setState({Account: e}, ()=>{this.setReport()}) }}
Using mount :
it("should check button click event - Select ", () => {
baseProps.onClick.mockClear();
wrapper.find('CLASS YOUR TESTING').setState({
contactOptions:[],
Account:[[""]],
accountOptions: [{ value: 'test', label: 'label test', accountBody: "test account" }],
showRequired: false,
loading:false
});
wrapper.update()
// wrapper.update()
wrapper.find('CLASS YOUR TESTING').find('Select').at(0).props().onChange({
contactBody:{
Accounts:[]
}})
onChange works at(0) and not at (1) . Why ?
The error means that:
let contactBody = contact.contactBody;
is undefined so now you should try to debug with console.log or other ways and see why it is undefined and find a Solution
Able to figure out
wrapper.find('CLASS YOUR TESTING').find('Select').at(1).props().onChange({
accountBody:{
LOA:{
Documents:{
Signers:[],
}
}
}
})

TypeError: Cannot read property 'roles' of undefined

I want the bot to change the color of the roles and it gives an error
client.guilds.get(servers[index]).roles.find('name', config.roleName).setColor(rainbow[place])
^
TypeError: Cannot read property 'roles' of undefined
at Timeout.changeColor [as _onTimeout] (C:\Users\1\Desktop\discord1\Role.js:29:38)
at ontimeout (timers.js:466:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:267:5)
Here is my code:
function changeColor() {
for (let index = 0; index < servers.length; ++index) {
client.guilds.get(servers[index]).roles.find('name', config.roleName).setColor(rainbow[place])
.catch(console.error);
if(config.logging){
console.log([ColorChanger] Changed color to ${rainbow[place]} in server: ${servers[index]});
}
if(place == (size - 1)){
place = 0;
}else{
place++;
}
}
}
You're getting this error because client.guilds.get('<id>') expects an exact guild id passed in as a String. See the comments in red under the .find method:
All collections used in Discord.js are mapped using their id property, and if you want to find by id you should use the get method. See MDN for details.
Therefore, the data stored at server[index] (in the 3rd line of your code) must not be a valid guild id.

Cannot read property call of undefined at Blockly.Generator.blockToCode

I am trying to add a custom text block. But when i enter any text in the input field, the error comes up.
"Uncaught TypeError: Cannot read property 'call' of undefined"
Blockly.Blocks['text_input']={
init:function()
{
this.appendDummyInput()
.appendField('Text Input:')
.appendField(new Blockly.FieldTextInput(''),'INPUT');
this.setColour(170);
this.setOutput(true);
}
};
this happens when the language definition for your custom type is missing.
// Replace "JavaScript" with the language you use.
Blockly.JavaScript['text_input'] = function(block) {
var value = Blockly.JSON.valueToCode(block, 'INPUT', Blockly.JavaScript.ORDER_NONE);
// do something useful here
var code = 'var x= "bananas"';
return code;
};

error: invalid input syntax for integer: when passing strings

I have the following function in node.js that makes a query to postgres based based on name_url. Sometimes it works and sometimes it just doesn't work.
Also I'm using lib pg-promise:
exports.getLawyerByUrlName = function (name_url, callback) {
console.log(typeof name_url) //NOTICE: output string
db.one({
text: "SELECT * FROM " + lawyersTable + " WHERE name_url LIKE $1::varchar",
values: name_url,
name: "get-lawyer-by-name_url"
})
.then(function (lawyer) {
callback(lawyer);
})
.catch(function (err) {
console.log("getLawyerByUrlName() " + err)
});
}
When it does not work it throws error:
getLawyerByUrlName() error: invalid input syntax for integer: "roberto-guzman-barquero"
This is a very weird bug I can't seem to catch why its happening. I'm checking before in console.log that I'm actually passing a string:
console.log(typeof name_url) //NOTICE: output string
My table field for name_url is:
CREATE TABLE lawyers(
...
name_url VARCHAR check(translate(name_url, 'abcdefghijklmnopqrstuvwxyz-', '') = '') NOT NULL UNIQUE,
It seems to be unlikely that that particular query could ever throw that error so I'll suggest three possibilities. The first is that the code that's causing the error is actually someplace else and that:
.catch(function (err) {
console.log("getLawyerByUrlName() " + err)
was cut and pasted into a different part of the code.
The 2nd possibility is that the "lawersTable" variable is getting populated with something unexpected.
The 3rd possibility is that my first two scenarios are wrong. ;-)

Resources