VSC 终端中的“CLIENT_MISSING_INTENTS”-discord.js v13
Posted
技术标签:
【中文标题】VSC 终端中的“CLIENT_MISSING_INTENTS”-discord.js v13【英文标题】:"CLIENT_MISSING_INTENTS" in VSC Terminal - discord.js v13 【发布时间】:2021-11-24 11:16:44 【问题描述】:我正在尝试制作一个不和谐的机器人,但它一直在说:[Symbol(code)]: 'CLIENT_MISSING_INTENTS` 我非常困惑为什么会这样做,我尝试研究但没有任何帮助。
我的代码:
import dotenv from 'dotenv'
dotenv.config()
const client = new DiscordJS.Client(
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILDS_MESSAGES
]
)
client.on('ready', () =>
console.log('The bot is ready')
)
if (message.content === 'amber')
message.reply(
content: 'Hello, I see that you have called for me, need anything?',
)
client.login(process.env.TOKEN)
【问题讨论】:
这是你的全部代码还是你遗漏了不和谐和意图的require
?
Intents
和 DiscordJS
来自哪里?
我相信GUILDS_MESSAGES
是一个无效的意图。应该是GUILD_MESSAGES
(没有“S”)
这能回答你的问题吗? Client Missing Intents when i try to launch it
【参考方案1】:
确保你做两件事:
1.) 确保您包含来自 discord.js
const Intents = require('discord.js');
2.) Intents.FLAGS.GUILDS_MESSAGES
应该是 Intents.FLAGS.GUILD_MESSAGES
。只需从GUILDS
中删除S
所以你的代码应该是这样的:
const DiscordJS = require('discord.js');
const Intents = require('discord.js');
import dotenv from 'dotenv'
dotenv.config()
const client = new DiscordJS.Client(
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
)
client.on('ready', () =>
console.log('The bot is ready')
)
if (message.content === 'amber')
message.reply(
content: 'Hello, I see that you have called for me, need anything?',
)
client.login(process.env.TOKEN)
【讨论】:
如果他们只使用模块导入,它将是import Client, Intents from "discord.js"
【参考方案2】:
快速修复:
import DiscordJS, Intents from 'discord.js'
import dotenv from 'dotenv'
dotenv.config()
const client = new DiscordJS.Client(
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
)
client.on('ready', () =>
console.log('The bot is ready')
)
client.on('messageCreate', (message) =>
if (message.content === 'amber')
message.reply(
content: 'Hello, I see that you have called for me, need anything?',
)
)
client.login(process.env.TOKEN)
您的代码中的错误:
1:
您忘记从“discord.js”导入“DiscordJS”
2:
你用过:
错误: Intents.FLAGS.GUILDS_MESSAGES
哪个是错的……正确的:
正确: Intents.FLAGS.GUILD_MESSAGES
3:
你得到了:
if (message.content === 'amber')
message.reply(
content: 'Hello, I see that you have called for me, need anything?',
)
在您的代码中,这是错误的,首先您应该创建一个在发送新消息时触发的事件。
示例:
client.on('messageCreate', (message) => // "message" will be the message that triggered the event
if (message.content === 'amber')
message.reply(
content: 'Hello, I see that you have called for me, need anything?',
)
)
【讨论】:
以上是关于VSC 终端中的“CLIENT_MISSING_INTENTS”-discord.js v13的主要内容,如果未能解决你的问题,请参考以下文章
尝试(和失败)在 VSC 终端中使用 tsc 在 Visual Studio Code 中运行(成功安装)TypeScript 编译器
VSC终端检测不到webpack版本号和打包报错的2020年解决方案