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/Utility/commands/VcdisconnectCmd.ts

50 lines
1.7 KiB
TypeScript
Raw Normal View History

import { VoiceChannel } from "discord.js";
import {
channelToConfigAccessibleChannel,
memberToConfigAccessibleMember,
userToConfigAccessibleUser,
2021-07-25 14:32:08 +02:00
} from "../../../utils/configAccessibleObjects";
2021-01-28 00:28:26 +01:00
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { utilityCmd } from "../types";
2021-01-28 00:28:26 +01:00
export const VcdisconnectCmd = utilityCmd({
trigger: ["vcdisconnect", "vcdisc", "vcdc", "vckick", "vck"],
description: "Disconnect a member from their voice channel",
usage: "!vcdc @Dark",
permission: "can_vckick",
signature: {
member: ct.resolvedMember(),
},
async run({ message: msg, args, pluginData }) {
if (!canActOn(pluginData, msg.member, args.member)) {
sendErrorMessage(pluginData, msg.channel, "Cannot move: insufficient permissions");
return;
}
if (!args.member.voice?.channelId) {
2021-01-28 00:28:26 +01:00
sendErrorMessage(pluginData, msg.channel, "Member is not in a voice channel");
return;
}
2021-07-04 23:14:12 +02:00
const channel = pluginData.guild.channels.cache.get(args.member.voice.channelId) as VoiceChannel;
2021-01-28 00:28:26 +01:00
try {
await args.member.voice.kick();
} catch {
2021-01-28 00:28:26 +01:00
sendErrorMessage(pluginData, msg.channel, "Failed to disconnect member");
return;
}
pluginData.state.logs.log(LogType.VOICE_CHANNEL_FORCE_DISCONNECT, {
mod: userToConfigAccessibleUser(msg.author),
member: memberToConfigAccessibleMember(args.member),
oldChannel: channelToConfigAccessibleChannel(channel),
2021-01-28 00:28:26 +01:00
});
2021-07-29 00:37:19 +01:00
sendSuccessMessage(pluginData, msg.channel, `**${args.member.user.tag}** disconnected from **${channel.name}**`);
2021-01-28 00:28:26 +01:00
},
});