[英]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_TOKEN
、 BOT_CLIENT_ID
、 GUILD_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:两件事情:
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
没有错误,因此它可能被安装为幻像依赖项。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.