Is it possible to selft mute a member with discord.js?

夙愿已清 提交于 2021-01-01 06:47:41

问题


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: sorry for my english, it's not my native language.


回答1:


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

The documentation for setSelfMute says:

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.



来源:https://stackoverflow.com/questions/60685914/is-it-possible-to-selft-mute-a-member-with-discord-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!