Discord 打不开

Discord won't turn on

我需要创建从电报到我的 discorcd 频道的桥梁,但是当我 运行 .js 脚本时我会收到错误消息。

      throw new TypeError('CLIENT_MISSING_INTENTS');
      ^

TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
    at Client._validateOptions (\dev\tele-discord-bot\node_modules\discord.js\src\client\Client.js:544:13)
    at new Client (\dev\tele-discord-bot\node_modules\discord.js\src\client\Client.js:73:10)
    at Object.<anonymous> (\dev\tele-discord-bot\bridge.js:19:14)
    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:79:12)
    at node:internal/main/run_main_module:17:47 {
  [Symbol(code)]: 'CLIENT_MISSING_INTENTS'
} 

这是错误,这是我使用的代码:

const TelegramBot = require('node-telegram-bot-api'); // https://github.com/yagop/node-telegram-bot-api
const Discord = require('discord.js'); // https://github.com/discordjs/discord.js

/* Values:
  token: Telegram bot token (logging into Telegram's API, you can get this from @BotFather on Telegram)
  token2: Discord bot token (logging into Discord's API, you can get this from Discord's developer docs > my apps > app)
  channelid: Discord channel ID (channel the Discord bot can access, right clicking a channel and clicking copy ID with developer mode enabled)
*/
const token = 'TELEGRAMTOKEN';
const token2 = 'DISCORDTOKEN';
const channelid = 'DISCRODCHANNELID';

/* Bots:
  bot: Telegram bot
  bot2: Discord bot
*/
const bot = new TelegramBot(token, {polling: true});
const bot2 = new Discord.Client();

// Matches "/echo [whatever]" in Telegram chat
bot.onText(/\/echo (.+)/, (msg, match) => {
  // 'msg' is the received Message from Telegram
  // 'match' is the result of executing the regexp above on the text content
  // of the message
  const chatId = msg.chat.id;
  const resp = match[1]; // the captured "whatever"

  // send back the matched "whatever" to the Telegram chat
  bot.sendMessage(chatId, resp);
});

// Listen for any kind of message in Telegram. There are different kinds of messages.
// Check out node-telegram-bot-api's GitHub & the Telegram API docs for more info 
// https://github.com/yagop/node-telegram-bot-api & https://core.telegram.org/api
bot.on('message', (msg) => {
  const chatId = msg.chat.id;
  console.log("we got a message from telegram");
  bot2.channels.get(channelid).send("[Telegram] **" + msg.from.first_name + " (@" + msg.from.username + "):** " + msg.text);
  console.log("sent that message to discord");
});

bot2.login(token2);

来源:https://gist.github.com/Ahe4d/866ef3b42cb5ca6ca7c84ff7da70828c

知道如何解决这个问题或出了什么问题吗?我以前从未与 discord.js 合作过 问候..

我猜你有一个 v8/9 基于网关的 discord 机器人....

https://discord.com/developers/docs/topics/gateway#privileged-intents

Gateway Intents
Intents are optionally supported on the v6 gateway but required as of v8

这是另一个阅读的好地方: https://discordjs.guide/additional-info/changes-in-v13.html#before-you-start

因此您需要将它们声明为客户端调用的一部分,例如:

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ready!');
});

// Login to Discord with your client's token
client.login(token);