【问题标题】:Discord bot Client not definedDiscord bot 客户端未定义
【发布时间】:2022-01-13 01:46:29
【问题描述】:

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

ReferenceError: Client is not defined
at Object.<anonymous> (C:\Users\Arya\Desktop\Arya\Discord\bot.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);

【问题讨论】:

  • 这是const { Client 不是const { Cient,它是client.login,不是bot.login,它是intents: 不是intent: 。确保你改正你的错别字

标签: javascript node.js json discord discord.js


【解决方案1】:

简单的语法错误,这可行:

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

您在底部的登录名让我混淆了 bot 变量的位置,但如果我的代码不起作用,您可以将其更改回来。否则你只需要在意图中添加一个 s。

【讨论】:

  • 错字并不总是 SyntaxErrors,在这种情况下,它是一个 ReferenceError 代替
【解决方案2】:
  • 您在代码的第二行定义 Cient 而不是 Client
  • 客户端选项必须指定intents: [ YOUR_INTENTS_HERE ] 而不是intent
  • 最后一行必须是client.login 而不是bot.login

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-13
    • 2021-04-16
    • 2019-03-25
    • 2019-06-26
    • 2019-09-04
    • 2021-10-28
    • 2021-12-20
    • 2022-01-10
    相关资源
    最近更新 更多