简体   繁体   English

Discord.js:一次静音多个用户

[英]Discord.js: Mute multiple users at once

I'm currently developing a discord bot that can mute/deafen part of a voice chat.我目前正在开发一个不和谐的机器人,它可以使语音聊天的一部分静音/耳聋。 It works, but I'm running into some issues.它有效,但我遇到了一些问题。 When the bot tries to mute a big group of players, they get muted one by one.当机器人试图让一大群玩家静音时,他们会被一个一个地静音。 When one of the players has a slower internet connection, all the players below them have to wait until that player gets muted.当其中一名玩家的互联网连接速度较慢时,他们下方的所有玩家都必须等到该玩家被静音。 This means a mute/unmute can take up to 10 seconds for 5 players, which is too long for the purpose I'm using it for.这意味着 5 个玩家的静音/取消静音最多可能需要 10 秒,这对于我使用它的目的来说太长了。

simplified code of the muting/deafening process:静音/震耳欲聋过程的简化代码:

this.players.forEach(player => {
  // If player belongs to group that has to be muted
  if ([condition]) {
    // Mute and undeafen player
    player.voice.setMute(true)
    player.voice.setDeaf(false)
  }
})

(where 'players' is an array with GuildMember objects) (其中“玩家”是一个包含 GuildMember 对象的数组)

My question is, is there a way to speed up this process?我的问题是,有没有办法加快这个过程? My solution would be to mute all players independently, but I have no idea how to implement this.我的解决方案是将所有玩家独立静音,但我不知道如何实现这一点。 I am thinking of using multithreading, but I'm not sure if this would even solve the problem, and I don't know how Javascript and Discord.js handle multithreading because I'm fairly new to JS.我正在考虑使用多线程,但我不确定这是否能解决问题,而且我不知道 Javascript 和 Discord.js 如何处理多线程,因为我对 JS 还很陌生。 So, does anyone have an idea how to tackle this problem?那么,有没有人知道如何解决这个问题? Thanks!谢谢!

I think whether multiple processes are slow or not is depend on your bot server and your discord server(your bot is in).我认为多个进程是否缓慢取决于您的机器人服务器和您的不和谐服务器(您的机器人在)。 Not your user's network.不是您用户的网络。 And basically js is synchronous, your process will be done at the almost same time.基本上 js 是同步的,您的过程将几乎同时完成。 (If you want async tasks, you can do it with then , Promise and async await .) (如果你想要异步任务,你可以用thenPromiseasync await 。)

Relieve worries little.减轻一点后顾之忧。

Thanks.谢谢。

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

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