You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
export default {
name: 'welcome',
aliases: ['ترحيب', 'الترحيب', 'setup_welcome'],
category: 'admin',
data: new SlashCommandBuilder()
.setName('welcome')
.setDescription('Configure the welcome system')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.addSubcommand((subcommand) =>
subcommand
.setName('setup')
.setDescription('Set up the welcome message')
.addChannelOption((option) =>
option
.setName('channel')
.setDescription('The channel to send welcome messages to')
.addChannelTypes(ChannelType.GuildText)
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('message')
.setDescription('Welcome message. Variables: {user}, {username}, {server}, {memberCount}')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('image')
.setDescription('URL of the image to include in the welcome message')
.setRequired(false)
)
.addBooleanOption((option) =>
option
.setName('ping')
.setDescription('Whether to ping the user in the welcome message')
.setRequired(false)
)
),
async execute(interaction, args = [], clientArg = null) {
// دعم استدعاء الأمر كـ Slash Interaction فقط (لأن فيه subcommand و options)
if (!interaction?.isChatInputCommand?.() && !interaction?.options?.getSubcommand) {
if (interaction?.reply) {
await interaction
.reply('استخدم الأمر بصيغة السلاش /welcome setup لتحديد إعدادات الترحيب.')
.catch(() => {});
}
return;
}
try {
const deferSuccess = await InteractionHelper.safeDefer(interaction);
if (!deferSuccess) {
logger.warn('Welcome interaction defer failed', {
userId: interaction.user.id,
guildId: interaction.guildId,
commandName: 'welcome',
});
return;
}
} catch (deferError) {
logger.error('Welcome defer error', { error: deferError.message });
return;
}
const { options, guild } = interaction;
const client = clientArg || interaction.client;
if (!guild) {
return await replyUserError(interaction, {
type: ErrorTypes.VALIDATION,
message: 'This command can only be used inside a server.',
});
}
if (!interaction.memberPermissions?.has(PermissionFlagsBits.ManageGuild)) {
return await replyUserError(interaction, {
type: ErrorTypes.PERMISSION,
message: 'You need the **Manage Server** permission to use `/welcome`.',
});
}
const subcommand = options.getSubcommand();
if (subcommand === 'setup') {
const channel = options.getChannel('channel');
const message = options.getString('message');
const image = options.getString('image')?.trim() || null;
const ping = options.getBoolean('ping') ?? false;
if (!channel) {
return await replyUserError(interaction, {
type: ErrorTypes.VALIDATION,
message: 'Please select a valid text channel.',
});
}
const existingConfig = await getWelcomeConfig(client, guild.id);
if (existingConfig?.channelId) {
logger.info(
`[Welcome] Setup blocked because config already exists in channel ${existingConfig.channelId} for guild ${guild.id}`
);
return await replyUserError(interaction, {
type: ErrorTypes.UNKNOWN,
message: `Welcome is already configured for <#${existingConfig.channelId}>. Use **/greet dashboard** to customize channel, message, ping, or image.`,
});
}
if (!message || message.trim().length === 0) {
logger.warn(`[Welcome] Empty message provided by ${interaction.user.tag} in ${guild.name}`);
return await replyUserError(interaction, {
type: ErrorTypes.VALIDATION,
message: 'Welcome message cannot be empty.',
});
}
if (image && !isValidHttpUrl(image)) {
logger.warn(`[Welcome] Invalid image URL provided by ${interaction.user.tag}: ${image}`);
return await replyUserError(interaction, {
type: ErrorTypes.VALIDATION,
message: 'Please provide a valid image URL (must start with http:// or https://).',
});
}
try {
await updateWelcomeConfig(client, guild.id, {
enabled: true,
channelId: channel.id,
welcomeMessage: message.trim(),
welcomeImage: image || undefined,
welcomePing: ping,
});
logger.info(
`[Welcome] Setup configured by ${interaction.user.tag} for guild ${guild.name} (${guild.id})`
);
const previewMessage = formatWelcomeMessage(message.trim(), {
user: interaction.user,
guild,
});
const embed = new EmbedBuilder()
.setColor(getColor('success'))
.setTitle('Welcome System Configured')
.setDescription(`Welcome messages will now be sent to ${channel}`)
.addFields(
{ name: 'Message Preview', value: truncateForEmbedField(previewMessage) },
{ name: 'Ping User', value: ping ? 'Yes' : 'No', inline: true },
{ name: 'Status', value: 'Enabled', inline: true }
)
.setFooter({ text: 'Tip: Use /greet dashboard to customize welcome settings' });
if (image) {
embed.setImage(image);
}
await InteractionHelper.safeEditReply(interaction, { embeds: [embed] });
} catch (error) {
logger.error(`[Welcome] Failed to setup welcome system for guild ${guild.id}:`, error);
await replyUserError(interaction, {
type: ErrorTypes.UNKNOWN,
message: 'An error occurred while configuring the welcome system. Please try again.',
});
}
}
},
};
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.