Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

how to translate discord.js decimals?

so basically what i wanted is to make the bot send a message in the serverLogs channel whenever a channel in that guild is deleted. The message sends general information about the deleted channel, but i wanted to expand this embed to make it say what permission overwrites dide that channel have so i tried console logging it to see what kind of info i get.

client.on('channelDelete', (channel) => {
    if(channel.type === 'dm') return;
    const serverLogs = channel.guild.channels.cache.get(serverLog);
    if (typeof serverLogs !== 'undefined') {
        const embed = new Discord.MessageEmbed()
            .setColor('#DB0000')
            .setTimestamp()
            .setTitle('Channel Deleted')
            .addFields(
                { name:'name', value:channel.name, inline: false },
                { name:'Category', value:channel.parent, inline: false },
                { name:'created at', value:`${moment(channel.createdAt).format('MMMM Do YYYY, h:mm:ss a')}`, inline: false },
                { name:'ID', value: channel.id, inline: false },
            );
        serverLogs.send(embed);

        // YOU CAN IGNORE ALL OF THE ABOVE

        channel.permissionOverwrites
            .each(E=>console.log(`<@${E.id}>`))
            .each(E=>console.log(E.deny))
            .each(E=>console.log(E.allow));
/*output 
<@/*id here hehe*/>
Permissions { bitfield: 16 } //wtf is 16
Permissions { bitfield: 1024 }// wtf is 1024
*/ 
    }
});

Is there a way to translate these decimals to normal permission Flags so i can read and manipulate them easier

question from:https://stackoverflow.com/questions/66062106/how-to-translate-discord-js-decimals

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can translate bitfield permissions into flags easily

console.log(new Discord.Permissions(16).toArray());
// Output in console:
// [ 'MANAGE_CHANNELS' ]

Where the "16" is, that is where you would put the bitfield number.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...