ChristopherBThai / Discord-OwO-Bot

A Discord bot that will keep track of your OwO
https://discordapp.com/oauth2/authorize?client_id=408785106942164992&permissions=1074120776&scope=bot
Other
556 stars 407 forks source link

error: TypeError: Cannot read properties of undefined (reading '0') #363

Open koderbilal opened 1 year ago

koderbilal commented 1 year ago

When I type owo h it gives the following error

how can i solve this error?

Unhandled rejection at: Promise  [object Promise] reason:  TypeError: Cannot read properties of undefined (reading '0')

image

Wifus commented 1 year ago

By checking out animalUtil.js:116:39, the top of the error stack trace, it is clear that the cpatreon property of the animals object is undefined.

let patreonPercent = animals.cpatreon[0] + animals.patreon[0];

Looking at where animals is initialized at the top of animalUtil.js, it seems like animals gets its data from owo-animals.json.

let animals;
try {
        animals = require('../../../../../tokens/owo-animals.json');
} catch (err) {
        console.error('Could not find owo-animals.json, attempting to use ./secret file...');
        animals = require('../../../../secret/owo-animals.json');
        console.log('Found owo-animals.json file in secret folder!');
}

Based on the other issues you have opened, it seems you've just copy pasted the owo-animals.json file from the secret folder into the tokens folder. This file is incomplete on purpose and does not include the most of the animal tiers, including cpatreon. This is the source of your issue. It can be fixed by either adding the missing tiers to owo-animals.json or removing the logic for those extra tiers (by commenting out lines 89-148 and 180-199 and fixing the if statements).

It's unlikely that somebody will be able to help you out with every issue like this you come across. Not many people have tried hosting their own instance of the bot. There are many things in the codebase excluded from the public repository. Also keep in mind the license this code is subject to. Commercial use of derivatives of the code is strictly prohibited.

All that being said have fun tinkering with the codebase, there are a lot of interesting things in here. If you run into any more issues, then giving a bit more information such as what you are trying to do or what you've done to try to fix the issue would be appreciated. I am not promising to hold your hand like I've done here though.