Cogmasters / concord

A Discord API wrapper library made in C
https://cogmasters.github.io/concord/
MIT License
523 stars 30 forks source link

Easy server member permission checking #150

Open Macintosh-Fan opened 1 year ago

Macintosh-Fan commented 1 year ago

Describe the feature

Check to see if server member has a permission of some sort.

u64bitmask discord_get_member_permissions(const struct discord_guild_member* member) {
    u64bitmask permissions = 0;
    for (int i = 0; i < member->roles->size; ++i) {
        permissions |= member->roles->array[i].permissions;
    }
    return permissions;
}

Though, maybe a function like bool discord_member_has_permission(const struct discord_guild_member* member, unsigned int code) (maybe unsigned int should be something else) could also be implemented.

Additional context

Discord chat (credit goes to @lcsmuller).

ThePedroo commented 1 year ago

I'm not sure where this would be used, since for that you would need the discord_guild_member, which in at least all Discord API responses I know, has permissions field available. As for the messages in #concord-help, it seems like there was a misunderstanding, since the MESSAGE_CREATE event doesn't include a member field

Edit: Nevermind, but Discord's get guild member only returns the IDs of the roles, you'll need to get them fetched, so in my opinion, we should find another approach to get the permissions