简体   繁体   English

如何使用多个令牌 DiscordJS

[英]How to use multiple tokens DiscordJS

I'm making custom bots for a project and i'm trying to connect multiple tokens with differents clients so i can manage every clients one by one我正在为一个项目制作自定义机器人,我正在尝试将多个令牌与不同的客户端连接起来,这样我就可以一个一个地管理每个客户端

My actual code is我的实际代码是

const tokens = ['token_1', 'token_2']
const { Client } = require('discord.js');

for(const token of tokens) {
const client = new Client();

client.on('ready', () => {
console.log(client.user.id)
});

client.login(token)
} 

But imagine i want the second bot to send a message in a channel, how do i do this?但是想象一下,我希望第二个机器人在频道中发送消息,我该怎么做?

Because if i put the channel.send in the for it will send the message with every bot, and i just want one bot, and i think client[0] does not work, if somebody can help it would be very cool因为如果我将channel.send放在 for 中,它将与每个机器人一起发送消息,我只想要一个机器人,我认为client[0]不起作用,如果有人可以帮助它会很酷

You can for example add a new array which will contain the clients例如,您可以添加一个包含客户端的新数组

const { Client } = require('discord.js');
const tokens = ['token_1', 'token_2'];
const clients = [];

for(const token of tokens) {
  const client = new Client();
  clients.push(client);

  client.on('ready', () => {
    console.log(client.user.id);
  });

  client.login(token);
}

clients[0] will now returns the first client clients[0]现在将返回第一个客户端

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM