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;
}
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;
}
}
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();
}
}
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;
}
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);
}
}
Aggregations