Skip to content

Instantly share code, notes, and snippets.

@Senither
Created February 14, 2018 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Senither/9cbc025a8259d44e9d514c4f00dbed94 to your computer and use it in GitHub Desktop.
Save Senither/9cbc025a8259d44e9d514c4f00dbed94 to your computer and use it in GitHub Desktop.
A simple "leave server command" made for Bramble from the AvaIre Central Discord server.
package com.avairebot.commands.system;
import com.avairebot.AvaIre;
import com.avairebot.commands.CommandMessage;
import com.avairebot.contracts.commands.SystemCommand;
import net.dv8tion.jda.core.entities.Guild;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class LeaveServerCommand extends SystemCommand {
public LeaveServerCommand(AvaIre avaire) {
super(avaire, false);
}
@Override
public String getName() {
return "Leave Server Command";
}
@Override
public String getDescription() {
return "Leaves the server the command was executed in, or the given ID.";
}
@Override
public List<String> getTriggers() {
return Collections.singletonList("leave");
}
@Override
public List<String> getUsageInstructions() {
return Arrays.asList(
"`:command` - Leaves the server the command was run in.",
"`:command <server id>` - Leaves the server with the give id."
);
}
@Override
public boolean onCommand(CommandMessage context, String[] args) {
if (args.length == 0) {
context.makeInfo("Leaving the server now, goodbye :wave:")
.queue(ignored -> context.getGuild().leave().queue());
return true;
}
try {
Guild guildById = avaire.getShardManager().getGuildById(args[0]);
if (guildById == null) {
return sendErrorMessage(context, "Invalid guild ID given, you must give me a valid ID for the guild you want me to leave!");
}
context.makeInfo("Leaving :name :wave:")
.set("name", guildById.getName())
.queue(ignored -> guildById.leave().queue());
} catch (NumberFormatException e) {
return sendErrorMessage(context, "Invalid guild ID given, you must give me a valid ID for the guild you want me to leave!");
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment