You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Discord机器人命令代码以取消特定权限要求?

解决Discord机器人Help命令权限检查问题

嘿,别担心,重新捡回项目遇到小问题太正常了!你的help命令现在会过滤掉用户没有权限的命令,咱们只需要把两处权限检查的代码删掉就行,很简单:

修改后的完整代码

我帮你移除了所有权限检查逻辑,同时保留了ownerOnly的验证(如果连服务器所有者专属命令的限制也想去掉,直接删掉那两行ownerOnly判断代码就行):

const { MessageEmbed } = require("discord.js")

module.exports = {
name: 'help',
description: "Lists all the commands",
run: async function (message, args) {

        let command
        if (args.length) command = message.client.commands.get(args[0]) || message.client.commands.find(function(cmd) {
            aliases = cmd.aliases || []
            return aliases.includes(args[0])
        })
        if (command) {
            // 仅保留服务器所有者专属命令的限制,不需要可直接删除此行
            if (command.ownerOnly && message.author.id !== message.guild.ownerID) command = undefined
            if (command) {
                const embed = new MessageEmbed()
                .setTitle(`${message.client.config.prefix[0]}${command.name} ${command.expectedArgs ? ` ${command.expectedArgs}` : ''}${command.aliases ? ` [${command.aliases.join(' ')}]` : ''}`)
                .setDescription(`${command.description ? command.description : 'No description provided'}`)
                message.channel.send(embed)
            }
        }
    
        if (!command) {
            const embed = new MessageEmbed()
            .setDescription(`Prefixes: ${message.client.config.prefix.map(p => `\`${p}\``).join(' ')}\nTo get more information of a particular command, type \`${message.client.config.prefix[0]}${this.name} [command]\``)
            const categories = []
            const cmds = message.client.commands.array()
            for (const command of cmds) if (command.category && !categories.includes(command.category)) categories.push(command.category)
            for (const category of categories) {
                const commands = cmds.filter(function (cmd) {
                    let isOwner = true
                    // 仅保留服务器所有者专属命令的限制,不需要可直接删除此行
                    if (cmd.ownerOnly && message.author.id !== message.guild.ownerID) isOwner = false
                    return isOwner && cmd.category == category
                })
                if (commands.length) embed.addField(category.toUpperCase(), commands.map(command => `\`${command.name}\``).join(' '), true) 
            }
            message.channel.send(embed)
        }
    }

}

关键修改说明

  1. 单个命令详情模块:移除了检查command.permissions的整个代码块,现在不管用户有没有对应权限,只要找到命令就能查看详情。
  2. 命令总列表模块:同样删掉了检查cmd.permissions的逻辑,所有命令都会显示在分类列表中(除了ownerOnly标记的命令,非服务器所有者看不到,取消限制只需删除对应判断行)。
  3. 顺便移除了原代码中外链跳转的部分,改成纯代码格式显示命令名。

这样修改后,所有用户都能看到机器人的全部命令列表和详情,不再受权限限制啦!

内容的提问来源于stack exchange,提问作者ish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 18:45:46