簡體   English   中英

Discord.js v12 如何檢查某個頻道中的消息是否為視頻附件?

[英]Discord.js v12 How could I check if a message in a certain channel is a VIDEO attachment?

如果發送視頻附件,例如#video ,並且如果它實際上是視頻附件,我正在嘗試在某個頻道中制作機器人,如果它實際上是視頻附件,機器人將在該頻道中回復某些內容並將視頻附件復制到另一個頻道。 如果是短信,機器人只會刪除短信。 我目前沒有代碼,因為我不知道 lol.Ž

當前代碼:

const {MessageAttachment, Client} = require('discord.js');
const client = new Discord.Client();

client.on('message', msg => {

    if (msg.channel.id == '728664668834627705') { // Valiate a channel

        const attachments = (msg.attachments).array(); // Get list of attachments
        const attachment = attachments[0]; // Take the first attachment

        if (msg.content) return msg.delete() // Delet the message if it has conetnt

        if (attachments.length !== 0) {
            const nameArray = attachment.name.split('.'); //Split the name 
            const attEx = nameArray[nameArray.length - 1] //Grap the last value of the array.
            if (attEx == "mp4" || attEx == "Or what ever fromat you want") {
                // Note this doesn't check the file it check the format of the file.

                const channel = client.channels.cache.get(`728664692012089366`) // Get the channel you want to send to by id

                const snetAttachment = new MessageAttachment(attachment.proxyURL);
                return channel.send(snetAttachment)

            }
        }
        msg.delete() // Delete teh message fi it doesn't pass the validations
    }
})

我收到一個錯誤:DiscordAPIError:請求實體太大

我認為這可以滿足您的要求。

const {MessageAttachment, Client} = require('discord.js');
const client = new Client();


client.on('message', msg => {

    if (msg.channel.id == '728558310340427838') { // Valiate a channel

        const attachments = (msg.attachments).array(); // Get list of attachments
        const attachment = attachments[0]; // Take the first attachment

        if (msg.content) return msg.delete() // Delet the message if it has conetnt

        if (attachments.length !== 0) {
            const nameArray = attachment.name.split('.'); //Split the name 
            const attEx = nameArray[nameArray.length - 1] //Grap the last value of the array.
            if (attEx == "mp4" || attEx == "Or what ever fromat you want") {
                // Note this doesn't check the file it check the format of the file.

                const channel = client.channels.cache.get(`728558358013018152`) // Get the channel you want to send to by id


                const snetAttachment = new MessageAttachment(attachment.proxyURL);  // Send as attachment

                
                return channel.send(snetAttachment);

            }
        }


        msg.delete() // Delete teh message fi it doesn't pass the validations
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM