Way to check if a channel exists

后端 未结 3 1241
迷失自我
迷失自我 2021-01-24 22:24
module.exports.run = async (bot, message, args) => {

    let ticketreason = args[1];
    let ticketname = \"ticket\" + ticketreason;

    message.guild.createChannel         


        
3条回答
  •  执笔经年
    2021-01-24 22:52

    You can use .channels, which returns a collection of GuildChannels, from this collection you can use .exists() to check if the channel already exists in the guild.

    So something like this:

    if (message.guild.channels.exists('name', ticketname)) { //checks if there in an item in the channels collection that corresponds with the supplied parameters, returns a boolean
        message.reply(`The ${ticketname} channel already exists in this guild.`).catch(console.error);
        return; //prevents the rest of the code from being executed
    }
    
    // Code that creates the channel {ticketname}...
    

提交回复
热议问题