Implemented new Commands:
help - list all commands timestamp - convert date to timestamp (still in progress) about - Bot porpose (still in progress) ping - check bot availability
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const moment = require('moment'); // Install moment.js with `npm install moment`
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('timestamp')
|
||||
.setDescription('Convert a human-readable date to a Discord timestamp.')
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName('date')
|
||||
.setDescription('The date to convert (e.g., YYYY-MM-DD HH:mm)')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName('format')
|
||||
.setDescription('The format for the timestamp')
|
||||
.setRequired(false)
|
||||
.addChoices(
|
||||
{ name: 'Short time', value: 't' },
|
||||
{ name: 'Long time', value: 'T' },
|
||||
{ name: 'Short date', value: 'd' },
|
||||
{ name: 'Long date', value: 'D' },
|
||||
{ name: 'Full date and time', value: 'f' },
|
||||
{ name: 'Full date and time with weekday', value: 'F' },
|
||||
{ name: 'Relative time', value: 'R' },
|
||||
)),
|
||||
async execute(interaction) {
|
||||
// Get user input
|
||||
const dateInput = interaction.options.getString('date');
|
||||
const format = interaction.options.getString('format') || 'f'; // Default to 'f' format
|
||||
|
||||
try {
|
||||
// Convert the date to a Unix timestamp
|
||||
const unixTimestamp = moment(dateInput, 'YYYY-MM-DD HH:mm').unix();
|
||||
|
||||
if (isNaN(unixTimestamp)) {
|
||||
return interaction.reply({
|
||||
content: 'Invalid date. Use the format `YYYY-MM-DD HH:mm`.',
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Construct the Discord timestamp
|
||||
const discordTimestamp = `<t:${unixTimestamp}:${format}>`;
|
||||
|
||||
// Reply with the result
|
||||
await interaction.reply(
|
||||
`Here’s your Discord timestamp:\n${discordTimestamp}`
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
await interaction.reply({
|
||||
content:
|
||||
'Invalid date format. Please use the format `YYYY-MM-DD HH:mm` (e.g., `2025-01-25 14:30`).',
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
const {SlashCommandBuilder} = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("about")
|
||||
.setDescription("Information about this bot"),
|
||||
async execute(interaction) {
|
||||
await interaction.reply({
|
||||
content: "This bot has some general commands for moderation, but includes on or two unqiue features, like the currenc system. It's a small project to enhanced the programming skills of the creator.",
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
const { SlashCommandBuilder} = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('help')
|
||||
.setDescription('Gives all available commands.'),
|
||||
async execute(interaction) {
|
||||
// Map over the full command objects to get names and descriptions
|
||||
const commandDetails = interaction.client.commands.map(cmd => ({
|
||||
name: cmd.data.name,
|
||||
description: cmd.data.description,
|
||||
}));
|
||||
|
||||
// Format the commands into a user-friendly help message
|
||||
const helpMessage = commandDetails
|
||||
.map(detail => `/${detail.name} - ${detail.description}`)
|
||||
.join('\n');
|
||||
|
||||
// Send the help message
|
||||
await interaction.reply(`Here are all the available commands:\n\n${helpMessage}`);
|
||||
|
||||
},
|
||||
};
|
||||
@@ -3,8 +3,8 @@ const { SlashCommandBuilder } = require('discord.js');
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Replies with Pong!'),
|
||||
.setDescription('Check if the bots responsivnes'),
|
||||
async execute(interaction) {
|
||||
await interaction.reply('Pong!');
|
||||
await interaction.reply({ content: 'Pong! (Online)', ephemeral: true });
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user