首页 > 解决方案 > 将 CURL 与 discord.js 和 5sim API 一起使用

问题描述

我试图为我的不和谐机器人发出命令,所以我可以通过他们的 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

所有帮助将不胜感激!

标签: apicurldiscorddiscord.jsbots

解决方案


你能试试吗

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();

因为你的语法不正确。


推荐阅读