【问题标题】:How to make an eval command?如何制作 eval 命令?
【发布时间】:2021-02-25 19:56:35
【问题描述】:

我目前的代码不起作用。

  const args2 = message.content.split(" ")
 
  if (message.content.startsWith("d!eval")) {
    if(!message.author.id == "749092490556080158") return;
    try {
      const code = args2.join(" ");
      let evaled = eval(code);
      
 
      if (!typeof evaled == "string")
        evaled = require("util").inspect(evaled);
 
      message.channel.send(clean(evaled), {code:"xl"});
    } catch (err) {
    console.log(err)
    message.channel.send(err)
    }
  }
  });

相反,它返回错误:

    at Client.<anonymous> (/home/runner/WorthySimplisticProblems/index.js:20:25)
    at Client.emit (events.js:315:20)
    at Client.EventEmitter.emit (domain.js:483:12)
    at MessageCreateAction.handle (/home/runner/WorthySimplisticProblems/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/home/runner/WorthySimplisticProblems/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/home/runner/WorthySimplisticProblems/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/home/runner/WorthySimplisticProblems/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/home/runner/WorthySimplisticProblems/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/runner/WorthySimplisticProblems/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (events.js:315:20)
(node:421) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (/home/runner/WorthySimplisticProblems/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async RequestHandler.push (/home/runner/WorthySimplisticProblems/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
(node:421) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:421) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我不知道如何解决它,如果有人可以留下 github 链接或类似的东西,将不胜感激!

【问题讨论】:

  • 你到底想要这个做什么?

标签: node.js discord discord.js eval


【解决方案1】:

这对我有用!

 if (message.content.startsWith("d!eval")) {
    if(!message.author.id == "749092490556080158") return;
    var result = message.content.split(" ").slice(1).join(" ")
        let evaled = eval(result);
        console.log(result)
        }

【讨论】:

    【解决方案2】:

    您忘记定义函数 clean()。 据我所知,使用它会正常工作

    const args2 = message.content.split(" ")
     
      if (message.content.startsWith("d!eval")) {
        if(!message.author.id == "749092490556080158") return;
        try {
          const code = args2.join(" ");
          let evaled = eval(code);
          
     
          if (!typeof evaled == "string") evaled = require("util").inspect(evaled);
          message.channel.send(evaled, {code:"xl"});
        } catch (err) {
        console.log(err)
        message.channel.send(err)
        }
      }
      });
    

    【讨论】:

      猜你喜欢
      • 2020-08-25
      • 2021-04-09
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-13
      • 1970-01-01
      • 2021-04-12
      相关资源
      最近更新 更多