TrueWinter / DiscordBot

My Discord bot. Development has been stopped
https://blog.truewinter.dev/2020/04/09/development-and-support-for-my-discord-bot-has-been-stopped
Apache License 2.0
46 stars 42 forks source link

Hide commands in the commands page #50

Closed DarkenLM closed 4 years ago

DarkenLM commented 4 years ago

Hello. I want to hide some commands, both in the Commands page of the dashboard and the commands command.

Any idea of how to do it?

TrueWinter commented 4 years ago

Hi,

I'm not sure if it was you or someone else, but someone did email me asking the same question. So I'll just copy my reply to that email to answer your question:

When running the help command, the only commands that are shown are the ones the user running the command has access to. Therefore, normal users do not see system commands when running this command. In the dashboard, the command list shows all commands.

While the bot doesn't have any built-in functionality to support hiding other commands, you are free to add this in if needed. The way I would do it is to add an property (for example, showInDashboard) in the exports.help function for each command and set this to true to show it, or false to hide it.

Let's say you want to hide the createinvite command in the dashboard, you would set the exports.help to something like:

exports.help = {
name: 'createinvite',
category: 'Moderation',
description: 'Creates an invite to the channel it is sent in. Example usage: `createinvite 1 5m` will create a single use invite valid for 5 mintues',
usage: 'createinvite [uses]\ncreateinvite [uses] [time (s/m/h/d)]',
showInDashboard: false
};

You would then add code into dashboard/templates/commands.ejs to detect that showInDashboard is false and then not add it. This should be the easiest part of it all. If you need the command also hidden in the help command (keep in mind that only the commands that a user has access to will be shown to them while running this command), you can repeat this process.

While I am always available for support, keep in mind that I offer the source code of the bot for free and am not obliged to provide support. It is also expected that people that change the bot try to understand the code and add to it before contacting me for additional assistance. Also note that changes to the bot may make support more difficult as I would not know about all of the changes.

DarkenLM commented 4 years ago

Thanks. I'll try to do what you said. And I only asked for help because I never used ejs before, and try to find the error with the method I tryed to use in the command.

DarkenLM commented 4 years ago

I've figured it out. First, I added showInDash: true in exports.conf in every command. Then I went to dashboard/templates/commands.ejs and added (Bold):

const help = {}; bot.commands.forEach((command) => { const cat = command.help.category; if (!help.hasOwnProperty(cat)) help[cat] = []; if (command.conf.showInDash) { help[cat].push(command); } });

And the help command I simpky deleted my method, because I haven't noticed the help command just show the commands the users are able to see with their permLevel.