51 lines
2.2 KiB
TypeScript
51 lines
2.2 KiB
TypeScript
|
import { SlashCommandBuilder, PermissionFlagsBits, ChannelType, ChatInputCommandInteraction, NewsChannel, TextBasedChannel, CategoryChannel, StageChannel, TextChannel, PrivateThreadChannel, PublicThreadChannel, VoiceChannel, APIInteractionDataResolvedChannel, ForumChannel } from "discord.js";
|
||
|
import { getSuccessEmbed } from "../tools/defaultEmbeds";
|
||
|
|
||
|
const builder = new SlashCommandBuilder();
|
||
|
builder.setName("logchannel");
|
||
|
builder.setDescription("Configures the log channel");
|
||
|
builder.setDMPermission(false);
|
||
|
builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels);
|
||
|
builder.addChannelOption((option) => {
|
||
|
option.addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement);
|
||
|
option.setName("Channel");
|
||
|
option.setDescription("The channel to send notifications to");
|
||
|
option.setRequired(true);
|
||
|
return option;
|
||
|
});
|
||
|
|
||
|
const execute = (interaction: ChatInputCommandInteraction) => {
|
||
|
const channel:TextBasedChannel = getTextBasedChannel(interaction.options.getChannel("Channel", true));
|
||
|
|
||
|
//TODO Save channel in config
|
||
|
|
||
|
const embed = getSuccessEmbed();
|
||
|
embed.setDescription(`Log channel has been set to <#${channel.id}>`);
|
||
|
interaction.reply({
|
||
|
embeds: [embed],
|
||
|
ephemeral: true
|
||
|
});
|
||
|
|
||
|
const logMessage = getSuccessEmbed();
|
||
|
logMessage.setDescription("This channel has been selected as the log channel");
|
||
|
logMessage.addFields({
|
||
|
name: "This action was performed by",
|
||
|
value: `${interaction.user.tag} (${interaction.user.id})`
|
||
|
});
|
||
|
channel.send({
|
||
|
embeds: [logMessage]
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function getTextBasedChannel(channel: CategoryChannel | NewsChannel | StageChannel | TextChannel | PrivateThreadChannel | PublicThreadChannel<boolean> | VoiceChannel | ForumChannel | APIInteractionDataResolvedChannel): TextBasedChannel {
|
||
|
if (channel.type === ChannelType.DM || channel.type === ChannelType.GroupDM || channel.type === ChannelType.GuildAnnouncement || channel.type === ChannelType.GuildText || channel.type === ChannelType.PublicThread || channel.type === ChannelType.PrivateThread || channel.type === ChannelType.GuildVoice) {
|
||
|
return channel as TextBasedChannel;
|
||
|
}
|
||
|
|
||
|
throw new TypeError("Channel is not a text based channel");
|
||
|
}
|
||
|
|
||
|
export {
|
||
|
builder,
|
||
|
execute
|
||
|
}
|