0
votes

I'm currently attempting to program the mute functionality onto a discord bot. It has the server permission "mute members" enabled.

This is the code that is getting run whenever I call the mute command:

if(!receiverG.mute) { 
                            message.channel.send(`${receiver} muted by ${sender}.`)
                            receiverG.setMute(true, remaining); 
                        } 
else {
                            message.channel.send(`${receiver} unmuted by ${sender}.`)
                            receiverG.setMute(false, remaining); 
}
message.channel.send(receiverG.mute); 

So, consecutive calls of this code should toggle mute, but message.channel.send.(receiverG.mute) sends "false" everytime, indicating that the member never got muted. I'm unclear how the mute functionality works with discord. I read somewhere that it's based on roles- if so, then what would be the point of a setMute() command?

Documentation: https://discord.js.org/#/docs/main/stable/class/GuildMember?scrollTo=setMute

1

1 Answers

3
votes

setMute() returns a promise. Therefore, you must wait for it to be completed before sending the status of the member.

await receiverG.setMute(true, remaining);

Remember that await can only be used in async functions. Make sure to also catch and handle an error if the promise were to be rejected (.catch() or try...catch).

As for the functionality of setMute(), it should be equivalent to right clicking on a member in a voice channel and selecting Server Mute.