- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的第一个 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
对象上使用它,而不能在您获得 targetUser
的 User
对象上使用,因为,我强烈建议对其进行编辑。
您可以继续获取 GuildMember
的 voiceState
并通过 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/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!