Add Discord.js bot base with prefix commands and Winston logging
Co-authored-by: yhqe <139268606+yhqe@users.noreply.github.com>
This commit is contained in:
1 parent
8bd000a57a
commit
e8049008eb
12 files changed
+1076
-2
No files matched your search
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
name: 'help',
|
||||
description: 'Lists all available commands or shows info about a specific one.',
|
||||
aliases: ['h', 'commands'],
|
||||
usage: 'help [command]',
|
||||
|
||||
execute(client, message, args) {
|
||||
const prefix = process.env.PREFIX || '!';
|
||||
|
||||
// Show info for a specific command
|
||||
if (args.length > 0) {
|
||||
const name = args[0].toLowerCase();
|
||||
const command = client.commands.get(name);
|
||||
|
||||
if (!command) {
|
||||
return message.reply(`No command found for \`${name}\`.`);
|
||||
}
|
||||
|
||||
const lines = [`**${prefix}${command.name}**`];
|
||||
if (command.description) lines.push(`> ${command.description}`);
|
||||
if (command.aliases?.length)
|
||||
lines.push(`> **Aliases:** ${command.aliases.map((a) => `\`${prefix}${a}\``).join(', ')}`);
|
||||
if (command.usage)
|
||||
lines.push(`> **Usage:** \`${prefix}${command.usage}\``);
|
||||
|
||||
return message.reply(lines.join('\n'));
|
||||
}
|
||||
|
||||
// Build a deduplicated command list (ignore aliases pointing to the same command)
|
||||
const seen = new Set();
|
||||
const commandList = [];
|
||||
|
||||
for (const command of client.commands.values()) {
|
||||
if (seen.has(command.name)) continue;
|
||||
seen.add(command.name);
|
||||
commandList.push(`\`${prefix}${command.name}\` — ${command.description || 'No description.'}`);
|
||||
}
|
||||
|
||||
return message.reply(
|
||||
`**Available commands:**\n${commandList.join('\n')}\n\nUse \`${prefix}help <command>\` for more details.`,
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
name: 'ping',
|
||||
description: 'Replies with Pong! and shows the bot latency.',
|
||||
aliases: ['pong'],
|
||||
usage: 'ping',
|
||||
|
||||
async execute(client, message) {
|
||||
const sent = await message.reply('Pinging…');
|
||||
const latency = sent.createdTimestamp - message.createdTimestamp;
|
||||
const apiLatency = Math.round(client.ws.ping);
|
||||
|
||||
await sent.edit(
|
||||
`🏓 Pong!\n> Bot latency: **${latency}ms** | API latency: **${apiLatency}ms**`,
|
||||
);
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user