Created
February 14, 2018 12:44
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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