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

如何在导入的JSON数据中使用.includes方法判断指定值是否存在

问题原因

includes()是数组的原型方法,你配置里的config.developer是对象结构,不支持直接调用该方法,所以逻辑执行报错。

修复方案

只需要修改权限判断那一行逻辑,先提取developer对象的所有值转为数组,再调用includes()匹配即可:

// 原有逻辑保留,仅修改判断行
const config = require("../../config.json");
const devsId = config.developer;

// 提取对象所有开发者ID值转为数组,再判断是否包含当前用户ID
if(!Object.values(devsId).includes(message.author.id)) return;

// 后续eval执行逻辑保持不变
try {
  const code = args.join(" ");
  let evaled = eval(code);
  if (typeof evaled !== "string") evaled = require("util").inspect(evaled);
  message.channel.send(`\`\`\`xl\n${clean(evaled)}\`\`\``);
} catch (err) {
  message.channel.send(`\`ERROR\` \`\`\`xl\n${clean(err)}\n\`\`\``);
}

可选兼容处理

如果存在message.author.id返回值为数字类型、和配置里的字符串ID类型不匹配的场景,可以做一层类型统一:

if(!Object.values(devsId).includes(message.author.id.toString())) return;

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 22:27:04