0
votes

i have made a bot for discord using java, using net.dv8tion.jda to manage the bot. I have made that when a new user enters the bot will send a private message to him, the problem is that some users have disabled the option to reveive messages from bots or from not in friend list users. So my idea was to make it in a new way, when a new user joins the server the bot will create a new textchannel called for example "welcome", in that channel the everyone role doesn't have the permission to see the channel, but the new user has the permission to see it. In that case would be a private channel that will be deleted after for example the user reads the rules and selects a name by typing "!name example".

My only problem is that i have done a lot of research, i did found how to modify permissions on specific roles using the bot, but i don't understand how to modify the permissions in the textchannels.

I have managed to create a new channel: event.getGuild().createTextChannel("welcome").complete(); and this creates a new textchannel named welcome.

Whith some research i have seen event.getGuild().createTextChannel("welcome").complete().getManager().putPermissionOverride(permHolder, allow, deny);

but still not sure what are the parameters, the "permHolder" is a IPermissionHolder interface, that has Member and Role subinterface, so i assume

event.getGuild().createTextChannel("welcome").complete().getManager().putPermissionOverride(event.getMember(), allow, deny); for modifying the new user permissions on that channel (the event is OnGuildMemberJoin)

and

event.getGuild().createTextChannel("welcome").complete().getManager().putPermissionOverride(event.getGuild().getRoleById(*everyone role id*), allow, deny); for modifying the everyone role permission on that channel

PS: yes i know in that way it will create 2 different channels named both "welcome", i should created first the channel, assign it to a variable and work on it after, but was just for understanding purpose here.

But i still don't know what allow and deny parameters are, are they a list of the permissions that i want to be allowed and those that i want to be deny? On Eclypse they are shown as long types. And if yes, how do i calculate them?

Sorry if what i have written may be confusing, and thank you in advance.

2

2 Answers

2
votes

You can modify permissions on the ChannelAction returned by createTextChannel. The addPermissionOverride method allows to add overrides for members and roles.

event.getGuild().createTextChannel("welcome")
    .addPermissionOverride(event.getMember(), EnumSet.of(Permission.VIEW_CHANNEL), null)
    .addPermissionOverride(role, null, EnumSet.of(Permission.VIEW_CHANNEL))
    .queue();
2
votes

I have solved the problem, after some research i concluded with

TextChannel canaleNuovo=event.getGuild().createTextChannel("welcome").complete();

canaleNuovo.getManager().getChannel().createPermissionOverride(event.getMember()).setAllow(Permission.VIEW_CHANNEL).queue();

canaleNuovo.getManager().getChannel().createPermissionOverride(event.getGuild().getRoleById("640568816702587041")).setDeny(Permission.VIEW_CHANNEL).queue();

And it works!