是否可以使用 discord.js 将成员静音?

时间:2022-11-19
本文介绍了是否可以使用 discord.js 将成员静音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

最近由于冠状病毒,学校停课了,所以我为我的班级制作了一个不和谐的服务器.人们对不和谐不是很熟悉,所以我想要一个可以让人们自我静音的命令,这样课程就可以开始了.如果他们想向老师提问,我希望每个人都能够取消静音,因此是自我静音而不是服务器静音.我已经尝试过这段代码,但它不起作用,因为 .selfmute(true) 是为机器人制作的.

Recently with coronavirus, school is cancelled so I made a discord server for my class. People are not very familiar with Discord so I want a command that can selfmute people so that the course can start. I want everyone to be able to unmute if they want to ask a question to the teacher, hence the self-mute and not the server-mute. I have tried this code but it's not working because the .selfmute(true) is made for the bot.

const Discord = require('discord.js');
const client = new Discord.Client();
const config = require("./config.json");

const prefix = "!";
client.on("message", (message) => {
if (!message.content.startsWith(prefix)) return;

if (message.content.startsWith(prefix + "mute")) {
    let channel = message.member.voice.channel;
    for (let member of channel.members) {
        member[1].voice.setSelfMute(true);
    }
}
});

client.login(config.token);

有人知道怎么做吗?感谢您的帮助.

Does anyone know how to do this ? Thanks for the help.

PS:对不起,我的英语不是我的母语.

PS: sorry for my english, it's not my native language.

推荐答案

很遗憾,您不能对客户端用户以外的用户进行自静音或自聋.

Unfortunately, you cannot self-mute or self-deafen a user other than the client's user.

setSelfMute 的文档 说:

为此语音状态自动静音/取消静音.

Self-mutes/unmutes the bot for this voice state.

此外,如果您尝试将不是客户端用户的用户自我静音,您将收到此错误:

Also, if you attempt to self-mute a user that will isn't the client user you will get this error:

Error [VOICE_STATE_NOT_OWN]: You cannot self-deafen/mute on VoiceStates that do not belong to the ClientUser.

<小时>

或者,您可以正常静音,然后使用命令取消静音.


Alternatively, you could mute them normally and then have a command to unmute them.

这篇关于是否可以使用 discord.js 将成员静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!