Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better help slash command + some other improvements #13

Merged
merged 8 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Custom
/config.json
.vscode/

# Logs
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.13.1
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (C) 2021 Naman Vrati

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,28 @@ npm run test

I'm working to make it more professional and easy to use for everyone. There will be a documentation out very soon.

## Authors
## People

👤 **Naman Vrati**
### Author

👤 **Naman Vrati**
- Website: https://namanvrati.cf/
- Twitter: [@namanvrati](https://twitter.com/namanvrati)
- Github: [@NamVr](https://github.com/NamVr)
- LinkedIn: [@namanvrati](https://linkedin.com/in/namanvrati)

👤 **Krish Garg**
### Contributors

👤 **Krish Garg**
- Website: https://krishgarg.ga/
- Twitter: [@KrishGa95586696](https://twitter.com/KrishGa95586696)
- Github: [@KrishGarg](https://github.com/KrishGarg)

👤 **Thomas Fournier**
- Website: https://artivain.com/
- Github: https://github.com/GoudronViande24
- Discord: `GoudronViande24#7211`

## 🤝 Contributing

Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/NamVr/DiscordBot-Template/issues). You can also take a look at the [contributing guide](https://github.com/NamVr/DiscordBot-Template/blob/master/CONTRIBUTING.md).
Expand All @@ -109,6 +116,6 @@ You can also [sponsor](https://ko-fi.com/namanvrati) the project and get listed
## 📝 License

Copyright © 2021 [Naman Vrati](https://github.com/NamVr).<br />
This project is [ISC](https://github.com/NamVr/DiscordBot-Template/blob/master/LICENSE) licensed.
This project is [ISC](LICENSE) licensed.

---
File renamed without changes.
59 changes: 48 additions & 11 deletions interactions/slash/misc/help.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* @file Sample help command with slash command.
* @author Naman Vrati
* @author Thomas Fournier <thomas@artivain.com>
* @since 3.0.0
* @version 3.1.0
*/

// Deconstructed the constants we need in this file.

const { MessageEmbed } = require("discord.js");
const { MessageEmbed, Collection } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
Expand All @@ -20,34 +22,69 @@ module.exports = {
option
.setName("command")
.setDescription("The specific command to see the info of.")
.setRequired(false)
),

/**
* @description Executes when the interaction is called by interaction handler.
* @author Naman Vrati
* @author Thomas Fournier <thomas@artivain.com>
* @param {*} interaction The interaction object of the command.
*/

async execute(interaction) {
/**
* @type {Object[]}
* @description Array of all slash commands objects earlier registered.
* @type {Collection}
* @description Collection of all slash commands
*/

const commands = interaction.client.slashCommands;

/**
* @type {Object[]}
* @description Help command's embed
* @type {string}
* @description The "command" argument
*/
let name = interaction.options.getString("command");

/**
* @type {MessageEmbed}
* @description Help command's embed
*/
const helpEmbed = new MessageEmbed()
.setColor(0x4286f4)
.setTitle("List of all my slash commands")
.setDescription(
"`" + commands.map((command) => command.data.name).join("`, `") + "`"
);

if (name) {
name = name.toLowerCase();
// If a single command has been asked for, send only this command's help.
// Added in version 3.1.0
helpEmbed.setTitle(`Help for \`${name}\` command`);
if (commands.has(name)) {
/**
* @type {SlashCommandBuilder}
* @description The command data
*/
const command = commands.get(name).data;
if (command.description) helpEmbed.setDescription(command.description + "\n\n**Parameters:**");
command.options.forEach(option => {
let content = option.description;
if (option.choices) {
let choices = "\nChoices: ";
option.choices.forEach(choice => choices += choice + ", ");
choices = choices.slice(0, -2);
content += choices;
};
if (!option.required) content += "\n*Optional*";
helpEmbed.addField(option.name, content.trim(), true);
});
} else {
helpEmbed.setDescription(`No slash command with the name \`${name}\` found.`).setColor("YELLOW");
};
} else {
// Give a list of all the commands
helpEmbed
.setTitle("List of all my slash commands")
.setDescription(
"`" + commands.map((command) => command.data.name).join("`, `") + "`"
);
};

// Replies to the interaction!

Expand Down
Loading