use of sx.blah.discord.util.RoleBuilder in project Discord4J by Discord4J.
the class RoleBot method handle.
/**
* Client is ready to interact with Discord.
* @see ReadyBot
*/
@Override
public void handle(ReadyEvent event) {
try {
// Gets the first guild the bot is a member of. (NOTE: This is only for demonstration. Getting guilds in this way is NOT recommended. Use IDs or events instead.)
IGuild guild = event.getClient().getGuilds().get(0);
// Instantiate a RoleBuilder which will aide in the creation of the role.
RoleBuilder roleBuilder = new RoleBuilder(guild);
// Set the new role's name
roleBuilder.withName("Awesome Role");
// Set the new role's color
roleBuilder.withColor(Color.GREEN);
// Make the new role display separately from others in Discord.
roleBuilder.setHoist(true);
// Allow this role to be mentionable in chat.
roleBuilder.setMentionable(true);
// Assign the Administrator permission to this role.
roleBuilder.withPermissions(EnumSet.of(Permissions.ADMINISTRATOR));
// Add the role to the guild in Discord.
IRole role = roleBuilder.build();
// Gets the user of the bot
IUser ourUser = event.getClient().getOurUser();
// Assigns our new role to the bot. NOTE: This will make the bot's ONLY role our role.
guild.editUserRoles(ourUser, new IRole[] { role });
} catch (MissingPermissionsException | RateLimitException | DiscordException e) {
// Error occurred
e.printStackTrace();
}
}
Aggregations