問題描述
最近由于冠狀病毒,學校停課了,所以我為我的班級制作了一個不和諧的服務器.人們對不和諧不是很熟悉,所以我想要一個可以讓人們自我靜音的命令,這樣課程就可以開始了.如果他們想向老師提問,我希望每個人都能夠取消靜音,因此是自我靜音而不是服務器靜音.我已經嘗試過這段代碼,但它不起作用,因為 .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 將成員靜音?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!