izy521 / discord.io

A small, single-file library for creating DiscordApp clients from Node.js or the browser
https://discord.gg/0MvHMfHcTKVVmIGP
MIT License
535 stars 155 forks source link

Cannot edit Channel permissions #291

Closed ERASFWGD00 closed 5 years ago

ERASFWGD00 commented 5 years ago

I'm trying to make it so that a channel is created and then permission overrides are set so that not everyone can see the new channel (in effect creating a new private channel)

A skimmed-down version of the code:

//where cid is the channel ID as a string & channelName is a string
bot.createChannel({ serverID: bot.channels[cid].guild_id, type: "text", name: channelName }, function (error, resp) {
                    bot.editChannelPermissions({ channelID: resp.id, roleID: resp.id, deny: 1024 });
});

Where bot is

var bot = new Discord.Client({
    autorun: true,
    token: config.token
});

I haven't gotten any errors from the actual 'editChannelPermissions' method, and I've tried switching 1024 for 0x00000400 as mentioned in the Discord documentation for VIEW_CHANNEL permissions Additionally, I can't quite see how to manually do it (taking the channel object, and manually adding the overwrites), as the whole thing kind of breaks down if I try to get channel.permmisions[role_ID].allow

I'm willing to give a fuller snippet of my code if it is necessary, but I've isolated the issue to the snippet provided. On a further note, I tried setting an override to a role already on the server using the same method, and though it does not work, it does create an override of sorts by adding the role to the overwritten permissions list, but with all permissions kind of at default (like shown below) no overrides

Any help would be appreciated

cloudrac3r commented 5 years ago

First of all: make you're on the community fork. npm install https://github.com/woor/discord.io/tarball/gateway_v6

I seem to remember making a patch so that permissions numbers work directly, not sure what's up with that.

Anyway, the right way to do it is this: bot.editChannelPermissions({channelID: "", roleID: "", deny: [Discord.Permissions.GENERAL_VIEW_CHANNEL]})

The deny value should be an array containing multiple constants. The complete list of constants can be found here: https://github.com/Woor/discord.io/blob/master/lib/index.js#L2756

ERASFWGD00 commented 5 years ago

Thank you! I figured there's another issue that made the code not work (specifically, using the channel ID instead of Server ID to get the @everyone role) I'll close the issue now. Thanks for your help!