首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不和谐不会打开

不和谐不会打开
EN

Stack Overflow用户
提问于 2021-08-30 21:36:01
回答 1查看 73关注 0票数 0

我需要创建从电报到我的不一致通道的桥,但是当我运行.js脚本时,我会收到错误。

代码语言:javascript
复制
      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'
} 

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

代码语言:javascript
复制
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合作过..

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-30 21:47:05

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

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

代码语言:javascript
复制
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

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

代码语言:javascript
复制
// 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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68990588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档