简体   繁体   English

discord.js.setToken(...) 不是 function

[英]discord.js .setToken(...) is not a function

I am new in discord.js v14.0.3 and trying to start a simple command but I got an error.我是discord.js v14.0.3的新手,尝试启动一个简单的命令,但出现错误。 I checked my BOT_TOKEN , BOT_CLIENT_ID , GUILD_ID is valid and I think the problem is not related with those token, how can I fix it?我检查了我的BOT_TOKENBOT_CLIENT_IDGUILD_ID是否有效,我认为问题与这些令牌无关,我该如何解决?

Error Message错误信息

> node register.js

/register.js:11
(async () => {
^

TypeError: (intermediate value).setToken(...) is not a function
    at Object.<anonymous> ....

My code我的代码

require("dotenv").config()

const { REST } = require('@discordjs/rest')
const { Routes } = require('discord.js')

const commands = [
  {
    name: 'ping',
    description: 'Replies with Pong!',
  },
];

const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN)

(async () => {
  try {
    console.log('Started refreshing application (/) commands.')

    await rest.put(Routes.applicationGuildCommands(process.env.BOT_CLIENT_ID, process.env.DC_GUILD_ID), { body: commands });

    console.log('Successfully reloaded application (/) commands.')
  } catch (error) {
    console.error(error)
  }
})()

package.json package.json

{
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js",
    "build": "node register.js"
  },
  "dependencies": {
    "discord.js": "^14.0.3",
    "dotenv": "^16.0.1",
    "ytdl-core": "^4.11.0"
  }
}

Two things:两件事情:

  1. Looks like your package.json is missing @discordjs/rest .看起来您的package.json缺少@discordjs/rest Install it with npm install @discordjs/rest or whatever your package manager is.使用npm install @discordjs/rest或您的 package 管理器安装它。 Since you have no error on the require it may be is installed as phantom dependency.由于您对require没有错误,因此它可能被安装为幻像依赖项。
  2. You simply missing a semicolon in the line const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN) therfore the whole block with ...setToken...(async () is considered to be one(.) expression.您只是在const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN)行中缺少一个分号,然后整个带有...setToken...(async ()的块被认为是是一个(。)表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM