'How do I disconnect a user from a discord channel with discord js?

The main issue seems to be that things are undefined. For example, a very simple version of something I have tried:

else if (message.content.startsWith("!dc")) {
    message.author.voice.setChannel(null);
}

Resulting in the terminal returning:

TypeError: Cannot read properties of undefined (reading 'setChannel')

I'm not quite sure how to "define" these as some solutions I've found online seem to do what I am trying to do in a similar way. Am I just missing something obvious?

I also have these Intents declared at the top.

const client = new Discord.Client({
intents: [
    Discord.Intents.FLAGS.GUILDS,
    Discord.Intents.FLAGS.GUILD_MESSAGES,
    Discord.Intents.FLAGS.GUILD_VOICE_STATES,
    Discord.Intents.FLAGS.GUILD_MEMBERS
    ]
});


Solution 1:[1]

As @Bee said in the comments to my question:

it'd be msg.member

Solution 2:[2]

Try this code:

message.member.voice.disconnect()
    .catch(console.error);

Solution 3:[3]

I don't think you can disconnect yourself while you are admin. So try this

return <member>.voice.setChannel(null)
    .then(() => message.channel.send(`Done`))
    .catch((err) => message.channel.send(`\\? | ${err}!`));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tomerikoo
Solution 2 Wolf Yuan
Solution 3