SimonLeclere / discord-easy-dashboard

💻 Simple module to facilitate the creation of dashboard using discord.js and express
https://www.npmjs.com/package/discord-easy-dashboard
71 stars 11 forks source link

TypeError: Cannot read properties of undefined (reading 'has') #30

Closed EclipseGame18 closed 1 year ago

EclipseGame18 commented 1 year ago

when I try to go into a guild to change settings, I get this error:

if (!member || !member.permissions.has("MANAGE_GUILD")) return res.redirect("/selector");
                                               ^

TypeError: Cannot read properties of undefined (reading 'has')

how do I resolve this?

SimonLeclere commented 1 year ago

Hello ! Can you send the complete error?

EclipseGame18 commented 1 year ago

Sure:

C:\Users\Desktop\T.B.T.D.A 2.0 Web Dashboard\node_modules\discord-easy-dashboard\routes\manage.js:11
if (!member || !member.permissions.has(req.dashboardConfig.permissions)) return res.redirect('/selector');
                                                          ^

TypeError: Cannot read properties of undefined (reading 'has')
    at C:\Users\Desktop\T.B.T.D.A 2.0 Web Dashboard\node_modules\discord-easy-dashboard\routes\manage.js:11:38
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v19.9.0
EclipseGame18 commented 1 year ago

perhaps member.permissions.has(MANAGE_GUILD) was changed in the newer versions of discord.js? from the docs, the new syntax is: member.permissions.has(PermissionsBitField.Flags.ManageGuild) (just a speculation)

SimonLeclere commented 1 year ago

The problem seems to be that member.permissions is set to undefined for some unknown reason. I would have to debug the module but I don't have much time right now. I might do it one day, in the meantime if you find a solution don't hesitate to open a pull request!

SimonLeclere commented 1 year ago

PS: duplicate of https://github.com/SimonLeclere/discord-easy-dashboard/issues/29

EclipseGame18 commented 1 year ago

I have found the problem: req.user.id turns up undefined

EclipseGame18 commented 1 year ago

when just using guild.members.fetch() i can get all members and info, when trying to filter with req.user.id it throws an error because there are no results to get permissions value form. I hope this will help with debugging! (when you get time)

SimonLeclere commented 1 year ago

Hey, which version of discord.js are you using ?

EclipseGame18 commented 1 year ago

The latest, but I also tried cloning the discord.js and module version from dash bot

SimonLeclere commented 1 year ago

Hey, can you test your code with the latest version published on github to check if your problem has been solved? Normally it should work with the latest version of Discord.js

EclipseGame18 commented 1 year ago

I tried it but I don't see any serves. nothing else is broken tho

SimonLeclere commented 1 year ago

Try setting "ManageGuild" as the permission required

SimonLeclere commented 1 year ago

The syntax is no longer MANAGE_GUILD but ManageGuild

EclipseGame18 commented 1 year ago

it works now, but with const setToggle = async(guild, value) guild seems to be null and value is the guild id

SimonLeclere commented 1 year ago

I'll check that

EclipseGame18 commented 1 year ago

thx

EclipseGame18 commented 1 year ago

would you like to see my code for that?

SimonLeclere commented 1 year ago

Yes that could help thanks!

EclipseGame18 commented 1 year ago
const setToggle = async(guild, value) => {
    await ToggleAntiSware.findOneAndUpdate({
        _id: guild.id
        },{
        _id: guild.id,
        toggle: value,

        },{
            upsert: true
        })
}
const getToggle = async(guild) => {
    const toggleSware = await ToggleAntiSware.findOne({_id: guild.id}).catch(error =>{
        console.log(`There was a error: ${error}`)
        })

        if (toggleSware.toggle == true){
            return true;
        } else{
            return false;
        }}

client.dashboard.addBooleanInput('Toggle sware detection', "enter either 'on' or 'off' to toggle the anti-swear function.", setToggle, getToggle);
EclipseGame18 commented 1 year ago

(i use mongoDB for storage)

SimonLeclere commented 1 year ago

Hey, the module works fine as it should. However, the set and get functions also take the client as a parameter.

const setter = (discordClient, guild, value) => { ... };
const getter = (discordClient, guild) => { ... };
SimonLeclere commented 1 year ago

Also here is a better version of your getter function :

const getToggle = async (discordClient, guild) => {
    const toggleSware = await ToggleAntiSware.findOne({ _id: guild.id }).catch(error =>{
        console.log(`There was a error: ${error}`);
    });

    return toggleSware.toggle || false;
};
EclipseGame18 commented 1 year ago

thx!

SimonLeclere commented 1 year ago

Did it work?

EclipseGame18 commented 1 year ago

yes

EclipseGame18 commented 1 year ago

everything works as expected

SimonLeclere commented 1 year ago

Perfect !