【问题标题】:Using CURL with discord.js and 5sim API将 CURL 与 discord.js 和 5sim API 一起使用
【发布时间】:2021-11-08 08:58:35
【问题描述】:

我正在尝试为我的不和谐机器人发出命令,因此我可以通过他们的 api 从 5sim 获取任何类型帐户的验证码...我认为我非常接近,因为我的一些代码在 https://reqbin.com/req/c-vdhoummp/curl-get-json-example.. 中工作。但我无法将它实施到我的命令中!这是我第一次使用 Curl,所以我不太熟悉,但我想知道是否有人可以帮助我解决我的损坏代码?

const Discord = require(`discord.js`)
const curl = require(`curl`)

module.exports = {
    name: `buynumber`,
    description: `buys a phone number!`,
    async execute(message) {
      const response = curl 'https://5sim.net/v1/user/buy/activation/cambodia/any/yahoo',
        {
          headers: {
            Authorization: "Bearer MYAUTHORIZATIONTOKENHERE",
            Accept: "application/json"
          }
         }; data = await response.json()


            message.channel.send(data.number)
    }}

我当前面临的错误是

[Sun Sep 12 2021 21:26:16] [LOG]   Initializing Startup!
[Sun Sep 12 2021 21:26:16] [ERROR] (node:12692) UnhandledPromiseRejectionWarning: C:\Users\manof\Desktop\Main Bots\Celly Bot\commands\buy.js:8
      const response = curl "https://5sim.net/v1/user/buy/activation/cambodia/any/discord",
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected string

所有帮助将不胜感激!

【问题讨论】:

    标签: api curl discord discord.js bots


    【解决方案1】:

    您正在尝试调用 curl 包中的函数 curl.get,因此它需要您通过 () 调用它,这是一个简单的语法错误,可以像这样修复:

    let data;
          const response = curl.get('https://5sim.net/v1/user/buy/activation/cambodia/any/yahoo',
            {
              headers: {
                Authorization: "Bearer MYAUTHORIZATIONTOKENHERE",
                Accept: "application/json"
              }
             });
    data = await response.json()
    

    我建议你阅读here给出的例子

    【讨论】:

      【解决方案2】:

      你能试试吗

      const response = curl('https://5sim.net/v1/user/buy/activation/cambodia/any/yahoo', {
          headers: {
              Authorization: "Bearer MYAUTHORIZATIONTOKENHERE",
              Accept: "application/json"
          }
      });
      const data = await response.json();
      

      因为你的语法不正确。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-24
        • 1970-01-01
        • 2011-04-01
        • 2016-06-26
        • 2016-02-14
        • 1970-01-01
        • 2014-03-06
        • 1970-01-01
        相关资源
        最近更新 更多