Base structure
This commit is contained in:
0
src/commands/index.ts
Normal file
0
src/commands/index.ts
Normal file
51
src/commands/notification.ts
Normal file
51
src/commands/notification.ts
Normal file
@ -0,0 +1,51 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user