Search in sources :

Example 1 with DiscordException

use of sx.blah.discord.util.DiscordException in project KaellyBot by Kaysoro.

the class AnnounceCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Matcher m = getMatcher(message);
        m.find();
        Language lg = Translator.getLanguageFrom(message.getChannel());
        String text = m.group(2).trim();
        if (m.group(1) != null) {
            for (IGuild guild : ClientConfig.DISCORD().getGuilds()) try {
                if (guild.getDefaultChannel().getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
                    Message.sendText(guild.getDefaultChannel(), text);
                else
                    Message.sendText(guild.getOwner().getOrCreatePMChannel(), text);
            } catch (DiscordException e) {
                LOG.warn("onReady", "Impossible de contacter l'administrateur de la guilde [" + guild.getName() + "].");
            } catch (Exception e2) {
                LOG.warn("onReady", e2);
            }
            Message.sendText(message.getChannel(), Translator.getLabel(lg, "announce.request.1") + " " + ClientConfig.DISCORD().getGuilds().size() + " " + Translator.getLabel(lg, "announce.request.2") + (ClientConfig.DISCORD().getGuilds().size() > 1 ? "s" : "") + ".");
        } else
            Message.sendText(message.getChannel(), text);
        return true;
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) DiscordException(sx.blah.discord.util.DiscordException) IGuild(sx.blah.discord.handle.obj.IGuild) DiscordException(sx.blah.discord.util.DiscordException)

Example 2 with DiscordException

use of sx.blah.discord.util.DiscordException in project S-argo by Expugn.

the class Sargo method buildBot.

@Nullable
private static IDiscordClient buildBot(String token) {
    ClientBuilder clientBuilder = new ClientBuilder();
    clientBuilder.withToken(token);
    try {
        return clientBuilder.login();
    } catch (DiscordException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : DiscordException(sx.blah.discord.util.DiscordException) ClientBuilder(sx.blah.discord.api.ClientBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with DiscordException

use of sx.blah.discord.util.DiscordException in project Discord4J by Discord4J.

the class ParrotBot method handle.

/**
 * Called when the client receives a message.
 */
@Override
public void handle(MessageReceivedEvent event) {
    // Gets the message from the event object NOTE: This is not the content of the message, but the object itself
    IMessage message = event.getMessage();
    // Gets the channel in which this message was sent.
    IChannel channel = message.getChannel();
    try {
        // Builds (sends) and new message in the channel that the original message was sent with the content of the original message.
        new MessageBuilder(this.client).withChannel(channel).withContent(message.getContent()).build();
    } catch (RateLimitException e) {
        // RateLimitException thrown. The bot is sending messages too quickly!
        System.err.print("Sending messages too quickly!");
        e.printStackTrace();
    } catch (DiscordException e) {
        // DiscordException thrown. Many possibilities. Use getErrorMessage() to see what went wrong.
        // Print the error message sent by Discord
        System.err.print(e.getErrorMessage());
        e.printStackTrace();
    } catch (MissingPermissionsException e) {
        // MissingPermissionsException thrown. The bot doesn't have permission to send the message!
        System.err.print("Missing permissions for channel!");
        e.printStackTrace();
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) MessageBuilder(sx.blah.discord.util.MessageBuilder) RateLimitException(sx.blah.discord.util.RateLimitException) IMessage(sx.blah.discord.handle.obj.IMessage) DiscordException(sx.blah.discord.util.DiscordException) MissingPermissionsException(sx.blah.discord.util.MissingPermissionsException)

Example 4 with DiscordException

use of sx.blah.discord.util.DiscordException in project Discord4J by Discord4J.

the class ShardImpl method getOrCreatePMChannel.

@Override
public IPrivateChannel getOrCreatePMChannel(IUser user) {
    checkReady("get PM channel");
    if (user.equals(getClient().getOurUser()))
        throw new DiscordException("Cannot PM yourself!");
    IPrivateChannel channel = privateChannels.get(user.getLongID());
    if (channel != null)
        return channel;
    ChannelObject pmChannel = client.REQUESTS.POST.makeRequest(DiscordEndpoints.USERS + getClient().getOurUser().getStringID() + "/channels", new PrivateChannelCreateRequest(user.getStringID()), ChannelObject.class);
    channel = (IPrivateChannel) DiscordUtils.getChannelFromJSON(this, null, pmChannel);
    privateChannels.put(channel);
    return channel;
}
Also used : ChannelObject(sx.blah.discord.api.internal.json.objects.ChannelObject) DiscordException(sx.blah.discord.util.DiscordException) PrivateChannelCreateRequest(sx.blah.discord.api.internal.json.requests.PrivateChannelCreateRequest)

Example 5 with DiscordException

use of sx.blah.discord.util.DiscordException in project Discord4J by Discord4J.

the class NickHolder method moveToVoiceChannel.

@Override
public void moveToVoiceChannel(IVoiceChannel channel) {
    IVoiceChannel oldChannel = getVoiceStateForGuild(channel.getGuild()).getChannel();
    if (oldChannel == null)
        throw new DiscordException("User must already be in a voice channel before they can be moved to another.");
    // client must have permission to both move members and connect to the channel.
    PermissionUtils.requirePermissions(channel, client.getOurUser(), Permissions.VOICE_MOVE_MEMBERS, Permissions.VOICE_CONNECT);
    try {
        ((DiscordClientImpl) client).REQUESTS.PATCH.makeRequest(DiscordEndpoints.GUILDS + channel.getGuild().getStringID() + "/members/" + id, DiscordUtils.MAPPER_NO_NULLS.writeValueAsString(new MemberEditRequest.Builder().channel(channel.getStringID()).build()));
    } catch (JsonProcessingException e) {
        Discord4J.LOGGER.error(LogMarkers.HANDLE, "Discord4J Internal Exception", e);
    }
}
Also used : DiscordException(sx.blah.discord.util.DiscordException) DiscordClientImpl(sx.blah.discord.api.internal.DiscordClientImpl) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

DiscordException (sx.blah.discord.util.DiscordException)20 ClientBuilder (sx.blah.discord.api.ClientBuilder)7 IChannel (sx.blah.discord.handle.obj.IChannel)4 MissingPermissionsException (sx.blah.discord.util.MissingPermissionsException)4 RateLimitException (sx.blah.discord.util.RateLimitException)4 Language (enums.Language)3 IDiscordClient (sx.blah.discord.api.IDiscordClient)3 IGuild (sx.blah.discord.handle.obj.IGuild)3 IMessage (sx.blah.discord.handle.obj.IMessage)3 IUser (sx.blah.discord.handle.obj.IUser)3 ProfileObject (com.github.vaerys.objects.ProfileObject)2 TrackLikes (com.github.vaerys.objects.TrackLikes)2 Matcher (java.util.regex.Matcher)2 EventDispatcher (sx.blah.discord.api.events.EventDispatcher)2 DiscordClientImpl (sx.blah.discord.api.internal.DiscordClientImpl)2 IReaction (sx.blah.discord.handle.obj.IReaction)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 CommandObject (com.github.vaerys.commands.CommandObject)1 ChannelSetting (com.github.vaerys.enums.ChannelSetting)1 UserSetting (com.github.vaerys.enums.UserSetting)1