gpt4 book ai didi

javascript - 我想在 discord.js v13 中使某人静音,但我在创建 VoiceState 对象时遇到问题

转载 作者:行者123 更新时间:2023-12-04 17:13:06 28 4
gpt4 key购买 nike

这是我的第一个 discord 机器人,我正试图让某人静音。根据我的理解,我认为我需要调用 VoiceState[.setMute()][1] 函数 我正在尝试创建一个我不理解数据含义的 voiceState 对象。

这是我的命令执行函数。 [/mute <@USER> ]

    async execute(interaction) {
const targetUser = interaction.options.getUser('target');

if (interaction.options.getNumber('seconds') !== null) {
const seconds = interaction.options.getNumber('seconds');
} else {
const seconds = 60;
}

console.log(targetUser);

const data = {} // APIVoiceState but idk what to put here
const voiceState = new VoiceState(interaction.guild, data );
console.log(voiceState);
voiceState.selfMute(true);

await interaction.reply('supposed to mute!');

Command Builder 代码(如果有人需要的话):

const data = new SlashCommandBuilder()
.setName('mute')
.setDescription('mute @user <seconds> server mutes the specified user for specified number of seconds')
.addUserOption(option =>
option.setName('target')
.setDescription('user to mute')
.setRequired(true))
.addNumberOption(option =>
option.setName('seconds')
.setDescription('Time in seconds the user stays muted (default: 60)'));

最佳答案

无需创建新的VoiceState对象,一旦GuildMember加入语音 channel API会自动提供该对象,我们只需要编辑GuildMember 的数据使用 GuildMemberEditData通过将属性 mute() 传递给它,所以要使用 GuildMemberEditData#mute() 方法,我们可以像这样:

  const targetUser = interaction.options.getMember('target');
targetUser.edit({mute : true})

请注意,您只能在 GuildMember 对象上使用它,而不能在您获得 targetUserUser 对象上使用,因为,我强烈建议对其进行编辑。

阿利特

您可以继续获取 GuildMembervoiceState 并通过 GuildMember#voice 对其使用 setMute()方法然后进一步使用 VoiceState#setMute()方法,在这种情况下我们的代码将是这样的:

 const targetUser = interaction.options.getMember('target');
targetUser.voice.setMute(true);

关于javascript - 我想在 discord.js v13 中使某人静音,但我在创建 VoiceState 对象时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69131845/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com