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

Update help.js #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
80 changes: 40 additions & 40 deletions 29-Dynamic-Help-Menu/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@ const loadCommands = require('./load-commands')
const { prefix } = require('../config.json')

module.exports = {
commands: ['help', 'h'],
description: "Describes all of this bot's commands",
callback: (message, arguments, text) => {
let reply = 'I am the tutorial bot, here are my supported commands:\n\n'

const commands = loadCommands()

for (const command of commands) {
// Check for permissions
let permissions = command.permission

if (permissions) {
let hasPermission = true
if (typeof permissions === 'string') {
permissions = [permissions]
}

for (const permission of permissions) {
if (!message.member.hasPermission(permission)) {
hasPermission = false
break
}
commands: ['help', 'h'],
description: "Describes all of this bot's commands",
callback: (message, arguments, text) => {
let reply = 'I am the tutorial bot, here are my supported commands:\n\n'

const commands = loadCommands()

for (const command of commands) {
// Check for permissions
let commandPermissions = command.permissions

if (commandPermissions) {
let hasPermission = true
if (typeof commandPermissions === 'string') {
commandPermissions = [commandPermissions]
}

for (const permission of commandPermissions) {
if (!message.member.hasPermission(permission)) {
hasPermission = false
break
}
}

if (!hasPermission) {
continue
}
}

// Format the text
const mainCommand =
typeof command.commands === 'string'
? command.commands
: command.commands[0]
const args = command.expectedArgs ? ` ${command.expectedArgs}` : ''
const { description } = command

reply += `**${prefix}${mainCommand}${args}** = ${description}\n`
}

if (!hasPermission) {
continue
}
}

// Format the text
const mainCommand =
typeof command.commands === 'string'
? command.commands
: command.commands[0]
const args = command.expectedArgs ? ` ${command.expectedArgs}` : ''
const { description } = command

reply += `**${prefix}${mainCommand}${args}** = ${description}\n`
}

message.channel.send(reply)
},
message.channel.send(reply)
},
}