Halo komunitas Stackoverflow. Saya cukup penasaran, mengenai acara channelUpdate di Discord.js, apakah mungkin untuk mengabaikan beberapa saluran tetapi mencatat sisanya?

bot.on("channelUpdate", async (oldChannel, newChannel) => {

        // Get stat channel IDs
        let totalUsers = oldChannel.guild.channels.get('667335552558956554');
        let onlineUsers = oldChannel.guild.channels.get('667335645894541331');
        let totalBots = oldChannel.guild.channels.get('667337560179343374');
        //Leave the stat channels alone, or too much logging will happen
        //.parent.id === '667335310350352394';
        if (totalUsers || onlineUsers || totalBots) return;

        let oldCategory = oldChannel.parent;
        let newCategory = newChannel.parent;
        let guildsChannel = newChannel.guild;
        if (!newCategory) newCategory = "None";
        if (!guildsChannel || !guildsChannel.available) return;

        let types = {
          "text"  : "Text channel",
          "voice" : "Voice channel",
          "null"  : "None"
        };

        const logchannel = channel.guild.channels.find(channel => channel.name === "server-logs")

        if (!logchannel) return;
        if (!logchannel.permissionsFor(oldChannel.guild.me).has('VIEW_CHANNEL')) return;
        if (!logchannel.permissionsFor(oldChannel.guild.me).has('SEND_MESSAGES')) return;

        if (oldChannel.name !== newChannel.name) {

        let channelNameUpdateEmbed = new Discord.RichEmbed()
        .setColor("#ffc500")
        .setDescription("Channel name updated.")
        .addField("Old channel name", `\`${oldChannel.name}\``, true)
        .addBlankField(true)
        .addField("New channel name", `\`${newChannel.name}\``, true)
        .addField("Channel type", `${types[newChannel.type]}`, true)
        .addBlankField(true)
        .addField("Channel category", `${newCategory}`, true)
        .setFooter(`Channel ID: ${newChannel.id} 🔥`)
        .setTimestamp()

        logchannel.send(channelNameUpdateEmbed).catch()

        }
});

Yang ditandai sebagai "Saluran Stat", apakah mungkin untuk mengabaikannya? Saluran log lain akan kebanjiran setiap kali anggota online atau offline

Terima kasih sebelumnya!

0
Mr.Dobby 8 Maret 2020, 18:43

1 menjawab

Jawaban Terbaik

Tentu, Anda dapat membuat arr ingoreChannel dan memeriksa apakah saluran di abaikan arr.

Seperti ini:

bot.on('channelUpdate', async (oldChannel, newChannel) => {
    const ignoreChannels = ['667335552558956554', '667335645894541331', '667337560179343374'];
    // Get stat channel IDs
    if (ignoreChannels.includes(oldChannel.id)) return;
    //Leave the stat channels alone, or too much logging will happen
    //.parent.id === '667335310350352394';

    let oldCategory = oldChannel.parent;
    let newCategory = newChannel.parent;
    let guildsChannel = newChannel.guild;
    if (!newCategory) newCategory = 'None';
    if (!guildsChannel || !guildsChannel.available) return;

    let types = {
        text: 'Text channel',
        voice: 'Voice channel',
        null: 'None',
    };

    const logchannel = channel.guild.channels.find(channel => channel.name === 'server-logs');

    if (!logchannel) return;
    if (!logchannel.permissionsFor(oldChannel.guild.me).has('VIEW_CHANNEL')) return;
    if (!logchannel.permissionsFor(oldChannel.guild.me).has('SEND_MESSAGES')) return;

    if (oldChannel.name !== newChannel.name) {
        let channelNameUpdateEmbed = new Discord.RichEmbed()
            .setColor('#ffc500')
            .setDescription('Channel name updated.')
            .addField('Old channel name', `\`${oldChannel.name}\``, true)
            .addBlankField(true)
            .addField('New channel name', `\`${newChannel.name}\``, true)
            .addField('Channel type', `${types[newChannel.type]}`, true)
            .addBlankField(true)
            .addField('Channel category', `${newCategory}`, true)
            .setFooter(`Channel ID: ${newChannel.id} 🔥`)
            .setTimestamp();

        logchannel.send(channelNameUpdateEmbed).catch();
    }
});
1
Cipher 8 Maret 2020, 17:25