首页 > 解决方案 > 不和谐.JS | 检查频道是否存在票务机器人

问题描述

所以再次你好,

我正在为不和谐制作一个票务机器人,但我遇到了这个我无法自己解决的错误。

这是创建票证命令:

    if(cmd === "new"){
    const reason = message.content.split(" ").slice(1).join(" ");
    if (message.guild.channels.exists("name", "ticket-" + message.author.username)) return message.channel.send(`You already have a ticket open.`);
    message.guild.createChannel(`ticket-${message.author.username}`, "text").then(c => {
        let role = message.guild.roles.find("name", "Support Team");
        let role2 = message.guild.roles.find("name", "@everyone");
        c.overwritePermissions(role, {
            SEND_MESSAGES: true,
            READ_MESSAGES: true 
        });
        c.overwritePermissions(role2, {
            SEND_MESSAGES: false,
            READ_MESSAGES: false
        });
        c.overwritePermissions(message.author, {
            SEND_MESSAGES: true,
            READ_MESSAGES: true
        });

        var embedcreated = new Discord.RichEmbed()
        .setColor("#f00202")
        .setDescription(`You ticket has been created ` + message.guild.channels.find(channel => channel.name === c.name).toString())
        .setTitle("Tickets | MiZ")
        .setFooter(`Tickets System`)
        .setTimestamp();

        message.channel.send(embedcreated);
        const embed = new Discord.RichEmbed()
        .setColor("#f00202")
        .addField(`Hey ${message.author.username}!`, ` Please explain your problen to the staff team.`)
        .setTimestamp();
        c.send({ embed: embed });
    }).catch(console.error);
    
    let sChannel = message.guild.channels.find(x => x.name === "logs");
    if(!sChannel) return message.channel.send("logs channel not found.")

    var staff = new Discord.RichEmbed()
    .setColor("#f00202")
    .addField("Created a ticket: " , message.author)
    .setTitle("Logs | MiZ")
    .setTimestamp();

    sChannel.send(staff)
}

我有一条线路可以检查频道是否存在,但它不起作用,因为我可以创建更多票证。

使用:Discord.js:^11.3.2

标签: discorddiscord.js

解决方案


请下次更具体并使用javascript块代码,这样更容易理解

no block code
"Javascript block code"

推荐阅读