mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-19 07:20:00 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { botControlCmd } from "../types";
|
|
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
import { TextChannel } from "discord.js";
|
|
|
|
export const LeaveServerCmd = botControlCmd({
|
|
trigger: ["leave_server", "leave_guild"],
|
|
permission: null,
|
|
config: {
|
|
preFilters: [isOwnerPreFilter],
|
|
},
|
|
|
|
signature: {
|
|
guildId: ct.string(),
|
|
},
|
|
|
|
async run({ pluginData, message: msg, args }) {
|
|
if (!pluginData.client.guilds.cache.has(args.guildId)) {
|
|
sendErrorMessage(pluginData, msg.channel as TextChannel, "I am not in that guild");
|
|
return;
|
|
}
|
|
|
|
const guildToLeave = await pluginData.client.guilds.fetch(args.guildId)!;
|
|
const guildName = guildToLeave.name;
|
|
|
|
try {
|
|
await pluginData.client.guilds.cache.get(args.guildId)?.leave();
|
|
} catch (e) {
|
|
sendErrorMessage(pluginData, msg.channel as TextChannel, `Failed to leave guild: ${e.message}`);
|
|
return;
|
|
}
|
|
|
|
sendSuccessMessage(pluginData, msg.channel as TextChannel, `Left guild **${guildName}**`);
|
|
},
|
|
});
|