Stack Overflow Asked by Yeti on November 16, 2021
So what I’m looking to do is make commands like ".help [command]" For example I have a ping command so I would like to run the command ".help ping" and then an embed would pop up showing a help embed for that command. My current command ".help" sends you a DM with the commands that I have entered into the DM Embed
help.js code
var Discord = require('discord.js');
module.exports = {
run: async(client, message, args) => {
message.channel.send(":bow_and_arrow: I've sent you a DM with a list of commands.")
const embed = new Discord.MessageEmbed()
.setColor("PURPLE")
.setTitle("Here is a list of all the bot commands!")
.setDescription('You can use `.help <command>` for more information')
.addField("Player Commands", "`.ping` | `.userinfo` | `.botinfo` | `.serverinfo`")
.addField("Moderation Commands", "`.` | `.` | `.` | `.`")
.addField("Admin Commands", "`.` | `.` | `.` | `.`")
.addField("Misc Commands", "`.` | `.` | `.` | `.`")
.addField("Developer Commands", "`.eval`")
message.author.send(embed);
}
}
you can do it something like this. Pretty much, im creating a collection and loading the commands (located in /commands/) getting their module.exports.help and setting it for the command handler. on a message I grab their message and try run module.exports.run (located in /commands/${command}). for the help command I check If they have arguments, if they do I attempt to get the command from the collection and return information about the command.
// Command Loader (main file)
var fs = require('fs')
client.commands = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
if (err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if (jsfile.length <= 0) {
console.log("Couldn't find commands.");
return;
}
console.log(`Loading ${jsfile.length} commands!`);
jsfile.forEach((f, i) => {
let props = require(`./commands/${f}`);
console.log(`${i + 1}: ${f} loaded!`);
client.commands.set(props.help.name, props);
});
});
// Client.on("message")
let prefix = "."
let [command, ...args] = msg.content.slice(prefix.length).split(/s+/g)
// Command handler
if (!message.content.startsWith(prefix)) return;
let commandfile = client.commands.get(command);
if (commandfile) commandfile.run(client, message, args);
// ./commands/ping.js
module.exports.run = async function (client, message, args) {
message.channel.send(`Latency Is: ```${Math.round(client.ping)}ms````)
}
module.exports.help = {
name: "ping",
description: "returns latency of bot",
usage: ".ping",
aliases: ['.latency', '.ping']
}
./commands/help.js
module.exports.run = async (client, message, args) => {
if (args[0]) {
let command = args[0]
if (client.commands.has(command)) {
command = client.commands.get(command);
var shEmbed = new Discord.MessageEmbed()
.setColor("PURPLE")
.setAuthor("______ HELP", message.guild.iconURL)
.setDescription(`The Bot Prefix Is: .nn**Command:** ${command.help.name}n**Description:** ${command.help.description || "No Description"}n**Usage:** ${command.help.usage || "No Usage"}n **Aliases** ${command.help.aliases || "No Aliases"}`);
message.channel.send(shEmbed)
}
if (!args[0]) {
message.delete();
let embed = new Discord.MessageEmbed()
.setAuthor("Help Command", message.guild.iconURL)
.setColor("PURPLE")
.setDescription(`${message.author.username} I've Sent You A DM! Check It Out`);
let sembed = new Discord.MessageEmbed()
.setColor("PURPLE")
.setAuthor(`_______ HELP`, message.guild.iconURL)
.setThumbnail(bot.user.displayAvatarURL)
.setTimestamp()
.setDescription(`These are the avaliable commands for the _______n the bot prefix is .`)
.addField(`commands:`, `YOUR COMMANDS_HERE`)
.setFooter(`_______ Version: ${version}`, bot.user.displayAvatarURL)
message.channel.send(embed).then(m => m.delete(10000));
message.author.send(sembed);
}
}
}
module.exports.help = {
name: "help"
}
Answered by L9 ego on November 16, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP