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

Small question #103

Closed
buttermiilk opened this issue Feb 11, 2021 · 6 comments
Closed

Small question #103

buttermiilk opened this issue Feb 11, 2021 · 6 comments
Labels
question Further information is requested

Comments

@buttermiilk
Copy link
Contributor

Uh, if I try to make some sort of NSFW commands in a separate group, how can I hide it when executing m!help in non-NSFW channels?
(I know this question is silly, meh)

@maisans-maid
Copy link
Collaborator

Making these commands in a seperate group is the easiest way to do this:
In your commandfile, the group should be a nsfw tag or any tag you like to consider nsfe

group: 'nsfw',

Then, make sure that in your index.js file, the group name is included:

paths: [
    'action', 'anime', 'bot',
    'core', 'fun', 'moderation', 'music',
    'owner', 'setup', 'social','utility', 'nsfw'
  //                                         ^ right here
    ]

After this, you can hide the group when executing help command by filtering the group out
Inject this code under help.js#L72

if (command.group === 'nsfw'){
  return message.channel.send('oh no, this is a nsfw command!')
};

That will work for all cases, but if you want the command to be hidden only on non-nsfw channels, you can add a condition like:

if (command.group === 'nsfw' && !message.channel.nsfw){
  return message.channel.send('oh no, this is a nsfw command!')
};

You can disable the nsfw command group or any command group from appearing on cmd command aswell by filtering out the group before mapping them out:
commands.js#L20 already filters out unspecified command groups (commands that were configured without a group variable), you can add the 'nsfw' group or whatever you named the command group to be excluded from the list.

for (const group of Object.keys(client.commands.groups).filter(g => !['unspecified', 'nsfw'].includes(g)))
//                                                                                      ^ group name to exclude here

@maisans-maid maisans-maid added the question Further information is requested label Feb 11, 2021
@buttermiilk
Copy link
Contributor Author

I've tried applying the last line for cmd.js, and instead of using if-else to hide the NSFW category in non-NSFW channels, I wanna know if I can use something else shorter?

@buttermiilk
Copy link
Contributor Author

I might send the code if you wish.

@maisans-maid
Copy link
Collaborator

maisans-maid commented Feb 12, 2021

I've tried applying the last line for cmd.js, and instead of using if-else to hide the NSFW category in non-NSFW channels, I wanna know if I can use something else shorter?

If you mean to display the nsfw commands in a nsfw channel, you can add a condition in the filter without using if-else

// Excludes nsfw on all channels
for (const group of Object.keys(client.commands.groups).filter(g => !['unspecified', 'nsfw'].includes(g)))
//                                                                                      ^ group name to exclude here

// Excludes nsfw on all channels except nsfw
const filternsfw = (nsfw) => nsfw === 'nsfw' ? message.channel.nsfw ? true : false : true;
// nsfw === 'nsfw'              -> Checks if the group name is nsfw
// message.channel.nsfw         -> Checks if the channel is nsfw
// true                         -> Do not filter out if the channel is not nsfw
// false                        -> Filter out if group name is nsfw and channel is nsfw
// true                         -> Do not filter out if group name is not nsfw
for (const group of Object.keys(client.commands.groups).filter(g => g !== 'unspecified' || filternsfw(g))){
//                                                                                              ^ use the function here

I have not tested the code on the local machine, but the logic should work

@buttermiilk
Copy link
Contributor Author

Doesn't seem to work, actually. I guess I'll use if-else for that.

@buttermiilk
Copy link
Contributor Author

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants