Search in sources :

Example 1 with EditChannel

use of io.discloader.discloader.entity.sendable.EditChannel in project DiscLoader by R3alCl0ud.

the class VoiceChannel method edit.

/**
 * Changes the channels settings
 *
 * @param name
 *            The new name for the channel
 * @param position
 *            The new position for the channel
 * @param bitrate
 *            The new {@link #bitrate}
 * @param userLimit
 *            The new {@link #userLimit}
 * @return A Future that completes with a voice channel if successful
 */
public CompletableFuture<IGuildVoiceChannel> edit(String name, int position, int bitrate, int userLimit) {
    CompletableFuture<IGuildVoiceChannel> future = new CompletableFuture<>();
    EditChannel d = new EditChannel(name, null, position, bitrate, userLimit);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(d), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildVoiceChannel channel = (IGuildVoiceChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), getGuild(), false);
            if (channel != null)
                future.complete(channel);
        }
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) EditChannel(io.discloader.discloader.entity.sendable.EditChannel) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel)

Aggregations

IGuildVoiceChannel (io.discloader.discloader.entity.channel.IGuildVoiceChannel)1 EditChannel (io.discloader.discloader.entity.sendable.EditChannel)1 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)1 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)1 CompletableFuture (java.util.concurrent.CompletableFuture)1