Bot-2.0/commands/help.js

113 lines
3.4 KiB
JavaScript
Raw Normal View History

2024-05-23 12:07:47 +00:00
//optiona name of the command
var fs = require('fs');
2024-06-08 08:33:57 +00:00
const { prefix } = require('../config.json');
2024-05-23 12:07:47 +00:00
function getAllCommands(client) {
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const allCommands = [];
for (const file of commandFiles) {
const command = require(`./${file}`);
allCommands.push(command);
}
return allCommands;
}
function allCommandsNames(guild = true)
{
//check if it is in dm or guild
if(guild)
{
const commands = getAllCommands();
let str = '';
for(const command of commands)
{
if(command.admin === false)
2024-06-08 08:33:57 +00:00
str += command.name + ', ';
2024-05-23 12:07:47 +00:00
}
return str;
}
else
{
const commands = getAllCommands();
let str = '';
for(const command of commands)
{
if(command.canBeUsedInDm)
if(command.admin === false)
2024-06-08 08:33:57 +00:00
str += command.name + ', ';
2024-05-23 12:07:47 +00:00
}
return str;
}
}
function getCommand(name, guild = true)
{
//check if it is in dm or guild
if(guild)
{
const commands = getAllCommands();
for(const command of commands)
{
if(command.name === name)
return command;
}
}
else
{
const commands = getAllCommands();
for(const command of commands)
{
if(command.name === name && command.canBeUsedInDm)
return command;
}
}
return null;
}
module.exports = {
name: 'help',
description: 'Get help with a command',
help: 'Get help with a command, you can also get a list of all commands',
options: [
{
name: 'command',
description: 'The command you want to get help with',
type: 3,
required: false,
},
],
slash: true,
text: true,
admin: false,
requireKick: false,
requireBan: false,
canBeUsedInDm: true,
contexts: ['GUILD_TEXT', 'GUILD_VOICE', 'DM'],
integration_types: [0,1],
execute: async (message, args) => {
if(args.length === 0)
{
const commands = allCommandsNames();
2024-06-08 08:33:57 +00:00
message.channel.send(`Hi, my prefix is \`${prefix}\`\nIf you want to get help with a command, type \`${prefix}help <command>\` or \`/help <command>\` \n` + commands);
2024-05-23 12:07:47 +00:00
return;
}
const command = getCommand(args[0]);
if(command === null)
{
//send all commands
const commands = allCommandsNames();
2024-06-08 08:33:57 +00:00
message.channel.send(`Hi, my prefix is \`${prefix}\`\nIf you want to get help with a command, type \`${prefix}help <command>\` or \`/help <command>\` \n` + commands);
2024-05-23 12:07:47 +00:00
return;
}
message.channel.send('Name: ' + command.name + '\nDescription: ' + command.description + '\nHelp: ' + command.help);
},
executeSlash: async interaction => {
const command = getCommand(interaction.options.getString('command'));
if(command === null)
{
//send all commands
const commands = allCommandsNames();
2024-06-08 08:33:57 +00:00
interaction.reply(`Hi, my prefix is \`${prefix}\`\nIf you want to get help with a command, type \`${prefix}help <command>\` or \`/help <command>\` \n` + commands);
2024-05-23 12:07:47 +00:00
return;
}
interaction.reply('Name: ' + command.name + '\nDescription: ' + command.description + '\nHelp: ' + command.help);
},
};