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

Is it possible to selft mute a member with discord.js?(是否可以使用 discord.js 将成员静音?)
本文介绍了是否可以使用 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 将成员静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 频道中的消息?)
how to make my bot mention the person who gave that bot command(如何让我的机器人提及发出该机器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修复必须使用导入来加载 ES 模块 discord.js)
How to list all members from a specific server?(如何列出来自特定服务器的所有成员?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修复“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服务器时的欢迎消息)