Message
Message
require('discord.js');
const ms = require('ms');
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
client.user.setActivity('your server', { type: 0 });
});
// Help Command
if (command === 'help') {
const embed = new EmbedBuilder()
.setTitle('Bot Command Help')
.setColor('Blue')
.setDescription('Here are the available commands:')
.addFields(
{ name: 'Moderation', value: '`ban`, `kick`, `mute`, `unmute`, `warn`,
`lock`, `unlock`, `purge`, `slowmode`' },
{ name: 'Utility', value: '`userinfo`, `serverinfo`, `avatar`, `addrole`,
`removerole`' },
{ name: 'Messaging', value: '`announce`, `dm`, `spam`' },
{ name: 'Giveaways', value: '`giveaway`, `end`, `reroll`' },
{ name: 'Fun/Other', value: '`profile`, `status`, `activity`' }
)
.setFooter({ text: 'Use &<command> to use a command.' });
// Mute Command
if (command === 'mute') {
const member = message.mentions.members.first();
if (!member) return message.reply('Please mention a user to mute!');
const duration = args[1];
if (!duration) return message.reply('Please specify a duration!');
// Kick Command
if (command === 'kick') {
const member = message.mentions.members.first();
if (!member) return message.reply('Please mention a user to kick!');
await member.kick();
message.reply(`${member.user.tag} has been kicked.`);
return;
}
// Ban Command
if (command === 'ban') {
const member = message.mentions.members.first();
if (!member) return message.reply('Please mention a user to ban!');
await member.ban();
message.reply(`${member.user.tag} has been banned.`);
return;
}
// Unmute Command
if (command === 'unmute') {
const member = message.mentions.members.first();
if (!member) return message.reply('Please mention a user to unmute!');
const muteRole = message.guild.roles.cache.find(role => role.name === 'Muted');
if (!muteRole) return message.reply('Muted role not found.');
await member.roles.remove(muteRole);
message.reply(`${member.user.tag} has been unmuted.`);
return;
}
// Warn Command
if (command === 'warn') {
const member = message.mentions.members.first();
if (!member) return message.reply('Please mention a user to warn!');
const reason = args.slice(1).join(' ') || 'No reason specified';
message.reply(`${member.user.tag} has been warned. Reason: ${reason}`);
return;
}
// Lock Command
if (command === 'lock') {
const channel = message.channel;
await channel.permissionOverwrites.edit(message.guild.roles.everyone,
{ SEND_MESSAGES: false });
message.reply('The channel has been locked.');
return;
}
// Unlock Command
if (command === 'unlock') {
const channel = message.channel;
await channel.permissionOverwrites.edit(message.guild.roles.everyone,
{ SEND_MESSAGES: true });
message.reply('The channel has been unlocked.');
return;
}
// Purge Command
if (command === 'purge') {
const amount = parseInt(args[0]);
if (isNaN(amount) || amount < 1 || amount > 100) return message.reply('Please
specify a valid number of messages to delete (1-100).');
await message.channel.bulkDelete(amount);
message.reply(`${amount} messages have been deleted.`);
return;
}
// Slowmode Command
if (command === 'slowmode') {
const time = parseInt(args[0]);
if (isNaN(time) || time < 1) return message.reply('Please specify a valid time
in seconds.');
await message.channel.setRateLimitPerUser(time);
message.reply(`Slowmode has been set to ${time} seconds.`);
return;
}
// Messaging Commands
if (command === 'announce') {
if (!message.member.permissions.has(PermissionsBitField.Flags.ManageMessages))
{
return message.reply('You need the "Manage Messages" permission to use this
command.');
}
const channel = message.mentions.channels.first();
const announcement = args.slice(1).join(' ');
if (!channel || !announcement) {
return message.reply('Please mention a channel and provide a message.');
}
const embed = new EmbedBuilder()
.setTitle('Announcement')
.setDescription(announcement)
.setColor('Gold')
.setTimestamp();
channel.send({ embeds: [embed] });
return;
}
const ms = require('ms');
const time = ms(duration); // Convert the duration into milliseconds
if (!time) {
return message.reply('Invalid duration format. Please use s, m, h, or d.');
}
// Set timeout for the giveaway to end after the specified duration
setTimeout(async () => {
const reaction = msg.reactions.cache.get('🎉');
if (!reaction) return message.channel.send('No reactions found.');
if (filtered.size === 0) {
return message.channel.send('No valid entries.');
}
const winners = filtered.random(winnersCount); // Randomly pick winners
from filtered users
message.channel.send(`🎉 Winner(s): ${winners.map(w => w.toString()).join(',
')}\nPrize: ${prize}`);
}, time); // End the giveaway after the specified duration
} // Close the 'giveaway' command block