Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
Make changes for help command
Browse files Browse the repository at this point in the history
  • Loading branch information
vachanmn123 committed Nov 3, 2021
1 parent 5888998 commit 17fecce
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 109 deletions.
14 changes: 7 additions & 7 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fs = require("fs");
const { Client, Collection, Intents } = require("discord.js");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const { token, client_id, test_guild_id } = require("./config.json");
const { token, client_id, test_guild_id, owner } = require("./config.json");
const DisTube = require('distube')
const SoundCloudPlugin = require('@distube/soundcloud')
const SpotifyPlugin = require('@distube/spotify')
Expand Down Expand Up @@ -54,6 +54,8 @@ for (const file of eventFiles) {
// Define Collection of Commands, Slash Commands and cooldowns

client.commands = new Collection();
client.version = "v1.0.0"
client.ownerID = owner
client.slashCommands = new Collection();
client.buttonCommands = new Collection();
client.selectCommands = new Collection();
Expand All @@ -69,8 +71,6 @@ client.distube = new DisTube.default(client, {
leaveOnStop: false,
plugins: [new SoundCloudPlugin.default(), new SpotifyPlugin.default()],
ytdlOptions: {
quality: "highestaudio",

filter: "audioonly",
quality: "highestaudio",
audioBitrate: 240000,
Expand All @@ -94,7 +94,7 @@ const commandFolders = fs.readdirSync("./commands");
// Loop through all files and store commands in commands collection.

for (const folder of commandFolders) {
if (folder==".DS_Store") {continue;}
if (folder===".DS_Store") {continue;}
const commandFiles = fs
.readdirSync(`./commands/${folder}`)
.filter((file) => file.endsWith(".js"));
Expand Down Expand Up @@ -140,12 +140,12 @@ const contextMenus = fs.readdirSync("./interactions/context-menus");
// Loop through all files and store slash-commands in slashCommands collection.

for (const folder of contextMenus) {
if (folder==".DS_Store") {continue;}
if (folder===".DS_Store") {continue;}
const files = fs
.readdirSync(`./interactions/context-menus/${folder}`)
.filter((file) => file.endsWith(".js"));
for (const file of files) {
if (folder==".DS_Store") {continue;}
if (folder===".DS_Store") {continue;}
const menu = require(`./interactions/context-menus/${folder}/${file}`);
const keyName = `${folder.toUpperCase()} ${menu.data.name}`;
client.contextCommands.set(keyName, menu);
Expand Down Expand Up @@ -260,7 +260,7 @@ const distubeEventFiles = fs
.filter((file) => file.endsWith(".js"));

// Loop through all files and execute the event when it is actually emmited.
const status = queue => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filters.join(", ") || "Off"}\` | Loop: \`${queue.repeatMode ? queue.repeatMode === 2 ? "All Queue" : "This Song" : "Off"}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``
// const status = queue => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filters.join(", ") || "Off"}\` | Loop: \`${queue.repeatMode ? queue.repeatMode === 2 ? "All Queue" : "This Song" : "Off"}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``
for (const file of distubeEventFiles) {
const event = require(`./events/distubeEvents/${file}`);
if (event) {
Expand Down
163 changes: 62 additions & 101 deletions commands/misc/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ module.exports = {
name: "help",
description: "List all commands of bot or info about a specific command.",
aliases: ["commands"],
usage: "[command name]",
usage: "help <category/command>",
cooldown: 5,
category: "misc",

/**
* @description Executes when the command is called by command handler.
Expand All @@ -24,105 +25,65 @@ module.exports = {
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const { commands } = message.client;

// If there are no args, it means it needs whole help command.

if (!args.length) {
/**
* @type {Object}
* @description Help command embed object
*/

let helpEmbed = new MessageEmbed()
.setColor(0x4286f4)
.setURL(process.env.URL)
.setTitle("List of all my commands")
.setDescription(
"`" + commands.map((command) => command.name).join("`, `") + "`"
)

.addField(
"Usage",
`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`
);

// Attempts to send embed in DMs.

return message.author
.send({ embeds: [helpEmbed] })

.then(() => {
if (message.channel.type === "dm") return;

// On validation, reply back.

message.reply({
content: "I've sent you a DM with all my commands!",
});
})
.catch((error) => {
// On failing, throw error.

console.error(
`Could not send help DM to ${message.author.tag}.\n`,
error
);

message.reply({ content: "It seems like I can't DM you!" });
});
}

// If argument is provided, check if it's a command.

/**
* @type {String}
* @description First argument in lower case
*/

const name = args[0].toLowerCase();

/**
* @type {Object}
* @description The command object
*/

const command =
commands.get(name) ||
commands.find((c) => c.aliases && c.aliases.includes(name));

// If it's an invalid command.

if (!command) {
return message.reply({ content: "That's not a valid command!" });
}

/**
* @type {Object}
* @description Embed of Help command for a specific command.
*/

let commandEmbed = new MessageEmbed()
.setColor(0x4286f4)
.setTitle("Command Help");

if (command.description)
commandEmbed.setDescription(`${command.description}`);

if (command.aliases)
commandEmbed
.addField("Aliases", `\`${command.aliases.join(", ")}\``, true)
.addField("Cooldown", `${command.cooldown || 3} second(s)`, true);
if (command.usage)
commandEmbed.addField(
"Usage",
`\`${prefix}${command.name} ${command.usage}\``,
true
);

// Finally send the embed.

message.channel.send({ embeds: [commandEmbed] });
async execute(message, args) {
// Get a lost of all commands
const commands = message.client.commands;
const commands_json = JSON.parse(JSON.stringify(commands));
const categories = [];
for(const command of commands_json) {
if(!categories.includes(command["category"])) {
categories.push(command["category"]);
}
}
if (String(message.author.id) !== message.client.ownerID) {
categories.splice(categories.indexOf('owner'), 1);
}
// If no args then send categories list
if (args.length === 0) {
const embed = new MessageEmbed()
.setColor(0x00ffff)
.setTitle(`${message.client.user?.tag} Help`)
.setDescription(`Use \`${prefix}help <command/category>\` for more info on a command.`)
.setFooter(`${message.client.user?.tag} ${message.client.version}`);
for(const category of categories) {
embed.addField(category, commands.filter(command => command["category"] == category).map(command => `\`${command["name"]}\``).join(", "));
}
message.channel.send({ embeds: [embed]});
// If category name is arg then send commands in that category
} else if(categories.includes(args[0])) {
const embed = new MessageEmbed()
.setColor(0x00ffff)
.setTitle(`${message.client.user?.tag} Help`)
.setDescription(`Use \`${prefix}help <command>\` for more info on a command.`)
.setFooter(`${message.client.user?.tag} v${message.client.version}`);
for(const command of commands_json) {
if(command["category"] == args[0]) {
embed.addField(command["name"], command["description"]);
}
}
message.channel.send({ embeds: [embed]});
// If command name is arg then send command info
} else if(commands.find(commands => commands["name"] == args[0])) {
try {
const embed = new MessageEmbed()
.setColor(0x00ffff)
.setTitle(`${message.client.user?.tag} Help`)
.setDescription(`Use \`${prefix}help <command>\` for more info on a command.`)
.setFooter(`${message.client.user?.tag} v${message.client.version}`);
const command = commands.find(command => command["name"] == args[0]);
embed.addField("Description", command["description"]);
embed.addField("Usage", command["usage"]);
if(command["aliases"]) embed.addField("Aliases", command["aliases"].join(", "));
message.channel.send({ embeds: [embed]});
} catch(e) {
console.log(e);
// Error occurs send an error message
message.channel.send(`\`${args[0]}\` is not a valid command or category`);
}
}
// If args is present but its neither command or category, send error message
else {
message.channel.send(`\`${args[0]}\` is not a valid command or category`);
}
},
};
12 changes: 11 additions & 1 deletion commands/misc/ping.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const {MessageEmbed} = require('discord.js');

/**
* @file Sample ping command
* @author Naman Vrati
Expand All @@ -6,6 +8,8 @@

module.exports = {
name: "ping",
description: "Pong!",
category: "misc",

/** You need to uncomment below properties if you need them. */
//description: 'Ping!',
Expand All @@ -21,6 +25,12 @@ module.exports = {
*/

execute(message, args) {
message.channel.send({ content: "Pong." });
embed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('Pong!')
.setDescription(`🏓Latency is ${Date.now() - message.createdTimestamp}ms.`)
.addField("API Latency", `${message.client.ws.ping}ms`, true)
.setTimestamp();
message.channel.send({ embeds: [embed] });
},
};
1 change: 1 addition & 0 deletions commands/misc/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
description: "Reloads a command",
args: true,
ownerOnly: true,
category: "owner",

/**
* @description Executes when the command is called by command handler.
Expand Down
1 change: 1 addition & 0 deletions commands/music/autoplay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
name: "autoplay",
description: "Turn on/off Autoplay",
category: "music",
usage: "autoplay",
guildOnly: true,
/**
Expand Down
1 change: 1 addition & 0 deletions commands/music/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
description: "Add filters to the playing song",
usage: "filters <filter>",
guildOnly: true,
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down
1 change: 1 addition & 0 deletions commands/music/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
description: "pause the playing song",
usage: "pause",
guildOnly: true,
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down
1 change: 1 addition & 0 deletions commands/music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
description: "Play a song",
usage: "play <song name>",
guildOnly: true,
category: "music",

/**
* @description Executes when the command is called by command handler.
Expand Down
1 change: 1 addition & 0 deletions commands/music/previous.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
description: "Plays the previous song",
usage: "previous",
guildOnly: true,
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down
1 change: 1 addition & 0 deletions commands/music/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
description: "show the queue",
usage: "queue",
guildOnly: true,
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down
1 change: 1 addition & 0 deletions commands/music/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
usage: "repeat <off/song/queue>",
guildOnly: true,
aliases: ["loop"],
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down
1 change: 1 addition & 0 deletions commands/music/resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
description: "Resume the paused song",
usage: "resume",
guildOnly: true,
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down
1 change: 1 addition & 0 deletions commands/music/seek.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
description: "seek to a position in the playing song",
usage: "seek <position>",
guildOnly: true,
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down
1 change: 1 addition & 0 deletions commands/music/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
description: "Skip the playing song",
usage: "skip",
guildOnly: true,
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down
1 change: 1 addition & 0 deletions commands/music/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
description: "Stop the playing song",
usage: "stop",
guildOnly: true,
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down
1 change: 1 addition & 0 deletions commands/music/volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
description: "Set the volume of the player",
usage: "volume <volume>",
guildOnly: true,
category: "music",
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
Expand Down

0 comments on commit 17fecce

Please sign in to comment.