3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-19 07:20:00 +00:00
zeppelin/backend/src/plugins/BotControl/commands/LeaveServerCmd.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-06-30 18:43:42 +02:00
import { Snowflake, TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { botControlCmd } from "../types";
2020-07-30 03:21:07 +03:00
export const LeaveServerCmd = botControlCmd({
2020-07-30 03:21:07 +03:00
trigger: ["leave_server", "leave_guild"],
permission: null,
config: {
preFilters: [isOwnerPreFilter],
},
signature: {
guildId: ct.string(),
},
async run({ pluginData, message: msg, args }) {
2021-06-30 18:43:42 +02:00
if (!pluginData.client.guilds.cache.has(args.guildId as Snowflake)) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "I am not in that guild");
2020-07-30 03:21:07 +03:00
return;
}
2021-06-30 18:43:42 +02:00
const guildToLeave = await pluginData.client.guilds.fetch(args.guildId as Snowflake)!;
2020-07-30 03:21:07 +03:00
const guildName = guildToLeave.name;
try {
2021-06-30 18:43:42 +02:00
await pluginData.client.guilds.cache.get(args.guildId as Snowflake)?.leave();
2020-07-30 03:21:07 +03:00
} catch (e) {
sendErrorMessage(pluginData, msg.channel as TextChannel, `Failed to leave guild: ${e.message}`);
2020-07-30 03:21:07 +03:00
return;
}
sendSuccessMessage(pluginData, msg.channel as TextChannel, `Left guild **${guildName}**`);
2020-07-30 03:21:07 +03:00
},
});