Discord机器人客户端未定义



我正试图制作一个不和谐的机器人,但遇到了一个问题:

ReferenceError: Client is not defined
at Object.<anonymous> (C:UsersAryaDesktopAryaDiscordbot.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47

代码是

require("dotenv").config();
const { Cient, Intents } = require("discord.js");
const client = new Client({
intent: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});
bot.login(process.env.TOKEN);

简单的语法错误,适用于:

require("dotenv").config();
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});
client.login(process.env.TOKEN);

你在底部的登录让我很困惑机器人变量在哪里,但如果我的代码不起作用,你可以把它改回来。否则,您只需要在intent中添加一个s。

  • 您在代码的第二行中定义的是Cient而不是Client
  • 客户端选项必须指定intents: [ YOUR_INTENTS_HERE ]而不是intent
  • 最后一行必须是client.login而不是bot.login

最新更新