简体   繁体   中英

Check if a channel is a voice channel (discord.js)

Im making a suggestion system but when you set the suggestion channel to a voice channel and make a suggestion the whole script errors.So i want to know if theres a way to tell the diffrence between a text channel and voice channel so if its a voice channel then i wanna return. But i dont know how to check if a channel is a voice or text channel.

We can use the Channel.type object to determine whether it is a voice channel or not.

First, we want to get the channel, using either the .get() or .find() functions, and then check the channel's type using a simple if statement:

const channelObject = message.guild.channels.cache.get('channel id here'); // Gets the channel object
if (channelObject.type === 'voice') return; // Checks if the channel type is voice

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM