【问题标题】:Server Mute Music Bot? .setDeaf is not a function?服务器静音音乐机器人? .setDeaf 不是函数吗?
【发布时间】:2020-11-03 14:09:35
【问题描述】:

所以我试图在我的机器人加入 VC 时将其静音,但我得到的只是

TypeError: bot.setDeaf is not a function

我也试过了

let bot = message.guild.members.cache.get('ID');

但这也没有用。 我究竟做错了什么?我真的找不到任何可以帮助我的地方。 这是其余的。提前致谢!

let bot = client.users.cache.get('ID');
bot.setDeaf(true);

【问题讨论】:

  • 看来你应该使用setSelfDeaf 而不是discord.js.org/docs/setSelfDeaf
  • 是的,我知道那个,但我看到其他机器人服务器自己静音,我只是想知道他们是怎么做到的?

标签: javascript node.js discord.js bots


【解决方案1】:

注意 1. 您只能从 VoiceState 调用 .setDeaf()。即使每个用户只能有一个 VoiceState,VoiceState 的范围也仅限于实例化的 GuildMember 实例。

注意2。您可以通过GuildMember.voice访问VoiceState属性,然后调用相关方法。

注意 3。 与其他人的建议相反,.setDeaf().setSelfDeaf() 之间存在细微差别。首先,.setDeaf() server-deafens 该语音状态的成员。这意味着该成员的语音状态旁边会有一个漂亮的红色图标。 。还会弹出审核日志的条目,您可以在.setDeaf()中指定原因。

另一方面,.setSelfDeaf() 只能在机器人的 VoiceState 上调用。库在内部检查 VoiceState 用户 ID 是否与客户端用户 ID 匹配。 (见https://github.com/discordjs/discord.js/blob/master/src/structures/VoiceState.js#L192) 自聋不会生成审核日志条目,并且bot旁边的图标将是灰色的,而不是红色的。

所以你的代码如下:

//exit if the voice state property does not exist
if(!message.guild.me.voice) return message.channel.send("I'm not in a voice channel...");

//deafen
message.guild.me.voice.setDeaf(true, "Yeah...this is a deafening test.").then(() => {
message.channel.send("I have successfully server deafened myself.");
});

您可以查看.setDeaf() here 的文档

【讨论】:

  • 哇,非常感谢我一直在寻找的东西,我真的不知道如何告诉机器人服务器静音,因为这是我在上面的代码中尝试的。哦,它也有效,再次感谢!
猜你喜欢
  • 2019-10-22
  • 2021-05-05
  • 2019-04-04
  • 1970-01-01
  • 2020-11-01
  • 2022-01-11
  • 2021-05-27
  • 2020-06-20
  • 2021-05-23
相关资源
最近更新 更多