首页 > 解决方案 > 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]: 必须为客户端提供有效的意图。

任何人都有想法我该如何解决这个问题?谢谢

标签: node.jsdiscorddiscord.js

解决方案


在 Discord.JS v13+ 上,您需要为客户端设置意图。

例子:

const discord = require('discord.js')
const Client = new discord.Client({
  intents: [ discord.Intents.FLAGS.GUILDS, discord.Intents.FLAGS.GUILD_MESSAGES ]
})

您可以在Discord 指南中查看更多信息

存在的所有意图是:

  • 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

推荐阅读