started to add bye messages
This commit is contained in:
parent
294af9c6af
commit
f37f0d492a
9 changed files with 300 additions and 92 deletions
111
src/commands/welcome_message/setupwelcomemessage.ts
Normal file
111
src/commands/welcome_message/setupwelcomemessage.ts
Normal file
|
@ -0,0 +1,111 @@
|
|||
import { SlashCommandBuilder, ChatInputCommandInteraction, PermissionFlagsBits } from "npm:discord.js";
|
||||
import { connectToDb, getGuild, getWelcomeConfig, addWelcomeConfig, setFeatureProperty, addGuild } from "../../libs/mysql.ts";
|
||||
import { errorEmbed, successEmbed } from "../../libs/discord.ts";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("setupwelcomemessage")
|
||||
.setDescription("Configure the Welcome message.")
|
||||
.setDMPermission(false)
|
||||
.addChannelOption(option =>
|
||||
option.setName("channel")
|
||||
.setDescription("The channel where the embed will be sent.")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addRoleOption(option =>
|
||||
option.setName("role")
|
||||
.setDescription("The role that will be ping if you put {role} in the message or the embed description.")
|
||||
.setRequired(false)
|
||||
)
|
||||
.addStringOption(option =>
|
||||
option.setName("message")
|
||||
.setDescription("The message that will be sent with the embed.")
|
||||
.setRequired(false)
|
||||
)
|
||||
.addStringOption(option =>
|
||||
option.setName("title")
|
||||
.setDescription("The title of the embed.")
|
||||
.setRequired(false)
|
||||
)
|
||||
.addStringOption(option =>
|
||||
option.setName("description")
|
||||
.setDescription("The description of the embed.")
|
||||
.setRequired(false)
|
||||
)
|
||||
.addStringOption(option =>
|
||||
option.setName("background")
|
||||
.setDescription("The url of background of the image of the embed.")
|
||||
.setRequired(false)
|
||||
)
|
||||
.addStringOption(option =>
|
||||
option.setName("vignette")
|
||||
.setDescription("The url of vignette of the embed.")
|
||||
.setRequired(false)
|
||||
),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
await interaction.deferReply()
|
||||
const connection = await connectToDb();
|
||||
|
||||
const guild_id = interaction.guild?.id ? interaction.guild?.id : ""
|
||||
|
||||
const guild = await getGuild(connection, guild_id)
|
||||
|
||||
if (!guild[0]) {
|
||||
await addGuild(connection, guild_id);
|
||||
}
|
||||
|
||||
const member = interaction.guild?.members.cache.get(interaction.user.id)
|
||||
|
||||
if (!member?.permissions.has(PermissionFlagsBits.Administrator) && !member?.roles.cache.has(guild[0]?.admin_role_id)) {
|
||||
const embed = errorEmbed("You are not allowed to use that command.", interaction.client.user.displayAvatarURL());
|
||||
|
||||
return await interaction.editReply({embeds: [embed]});
|
||||
}
|
||||
|
||||
const config = await getWelcomeConfig(connection, guild_id);
|
||||
|
||||
if (!config[0]) {
|
||||
await addWelcomeConfig(connection, guild_id);
|
||||
}
|
||||
|
||||
const channel_id = interaction.options.getChannel("channel")?.id
|
||||
const role_id = interaction.options.getRole("role")?.id
|
||||
const message = interaction.options.getString("message")
|
||||
const title = interaction.options.getString("title")
|
||||
const description = interaction.options.getString("description")
|
||||
const background_url = interaction.options.getString("background")
|
||||
const vignette_url = interaction.options.getString("vignette")
|
||||
|
||||
await setFeatureProperty(connection, guild_id, "welcome_config", "channel_id", channel_id ? channel_id : "");
|
||||
|
||||
if (role_id) {
|
||||
await setFeatureProperty(connection, guild_id, "welcome_config", "role_id", role_id);
|
||||
}
|
||||
|
||||
if (message) {
|
||||
await setFeatureProperty(connection, guild_id, "welcome_config", "message_format", message);
|
||||
}
|
||||
|
||||
if (title) {
|
||||
await setFeatureProperty(connection, guild_id, "welcome_config", "title", title);
|
||||
}
|
||||
|
||||
if (description) {
|
||||
await setFeatureProperty(connection, guild_id, "welcome_config", "description_format", description);
|
||||
}
|
||||
|
||||
if (background_url) {
|
||||
await setFeatureProperty(connection, guild_id, "welcome_config", "background_url", background_url);
|
||||
}
|
||||
|
||||
if (vignette_url) {
|
||||
await setFeatureProperty(connection, guild_id, "welcome_config", "vignette_url", vignette_url);
|
||||
}
|
||||
|
||||
connection.end();
|
||||
|
||||
const embed = successEmbed("Your welcome message has been successfully setup.", interaction.client.user.displayAvatarURL());
|
||||
|
||||
interaction.editReply({embeds: [embed]});
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue