node.js - DISCORD JS BOT - TypeError [CLIENT_MISSING_INTENTS]:必须为客户端提供有效的意图
问题描述
我得到上面的错误。
这是代码:
// token: ---------------------------------------------------
const token = ('') // a ''-k közé kell beírni a tokent-
// ----------------------------------------------------------
// channel id-k ----------------------------
const ofo = ('779369203572015134');
const magyar = ('797181568355008573');
const matematika = ('779368815364538398');
const angol = ('780147093850554408');
const tortenelem = ('780147128671797259');
const fizika = ('784325257754181632');
const biologia = ('784325257754181632');
const foldrajz = ('797181800661254144');
const rezidencia = ('821122601283747841');
const detox = ('743212240215212064');
const testgeneral = ('876043353593118725')
// -----------------------------------------
const schedule = require('node-schedule');
const Discord = require('discord.js');
const fs = require('fs');
const client = new Discord.Client();
client.on("ready", () => {
const job = schedule.scheduleJob({hour: 20, minute: 10}, () => {
const channel = client.channels.cache.get(testgeneral);
if (!channel) return console.error("ilen csatolna nincsen embe");
channel.join().then(connection => {
console.log("sikeres csatlakozás.");
}).catch(e => {
console.error(e);
});
});
client.login(token);
});
这是我输入“节点”时的错误代码。' : TypeError [CLIENT_MISSING_INTENTS]: 必须为客户端提供有效的意图。
任何人都有想法我该如何解决这个问题?谢谢
解决方案
在 Discord.JS v13+ 上,您需要为客户端设置意图。
例子:
const discord = require('discord.js')
const Client = new discord.Client({
intents: [ discord.Intents.FLAGS.GUILDS, discord.Intents.FLAGS.GUILD_MESSAGES ]
})
存在的所有意图是:
- Intents.FLAGS.GUILDS
- Intents.FLAGS.GUILD_MEMBERS
- Intents.FLAGS.GUILD_BANS
- Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS
- Intents.FLAGS.GUILD_INTEGRATIONS
- Intents.FLAGS.GUILD_WEBHOOKS
- Intents.FLAGS.GUILD_INVITES
- Intents.FLAGS.GUILD_VOICE_STATES
- Intents.FLAGS.GUILD_PRESENCES
- Intents.FLAGS.GUILD_MESSAGES
- Intents.FLAGS.GUILD_MESSAGE_REACTIONS
- Intents.FLAGS.GUILD_MESSAGE_TYPING
- Intents.FLAGS.DIRECT_MESSAGES
- Intents.FLAGS.DIRECT_MESSAGE_REACTION
- Intents.FLAGS.DIRECT_MESSAGE_TYPING
推荐阅读
- android - 为 Imageview 请求 RecyclerViewAdapter.notifyItemChanged 的示例
- ffi - 如何使用 Elmish 和 Fable 将参数从 html 页面传递到编译的 js 应用程序
- c# - 当状态码设置为 .net core 2.1 时,授权过滤器继续开启
- symfony - Symfony 上按 ID 列出的两个不同表的列表
- android-workmanager - WorkManager 自定义约束
- angular - 将服务中的布尔值链接到多个组件
- java - How to add tags when saving an object in an Algolia index using the Java API
- async-await - 运行 .sendKeys 后量角器挂起
- ios - 按下 backBarButton(来自 NavigationController)时如何播放声音?(对于斯威夫特)
- r-markdown - 使用 Blogdown 编写和读取 .rds 文件