Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

63
Visualizações
I'm looking to mute someone in discord.js v13 and i have problem in creating VoiceState object

This is my first discord bot and I'm trying to mute someone. Based on my understanding I think I need to invoke the [.setMute()][1] function of the VoiceState and I'm trying to create a voiceState object where I dont understand what the data means.

Heres my execute function for the command. [ /mute <@USER> <SECONDS(optional)> ]

    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 code if anyone needs it:

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)'));
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No need to create a new VoiceState object, once a GuildMember joins a voice channel the API automatically offers the object, we just need to edit the GuildMember's data using the GuildMemberEditData by passing the property mute() to it, so to utilize GuildMemberEditData#mute() method we can just go like:

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

Please note that you can only use it on a GuildMember object and not on an User object which you are getting targetUser as, I strongly recommend to edit that.

Aliter

You can go ahead and get the GuildMember's voiceState and use setMute() on that via the GuildMember#voice method then further use the VoiceState#setMute() method on it, in that case our code would be something like this:

 const targetUser = interaction.options.getMember('target');
 targetUser.voice.setMute(true);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda