Discord.js v12如何检查某个频道中的消息是否为VIDEO附件?

时间:2020-07-02 15:33:39

标签: javascript video discord discord.js

如果尝试通过视频附件(例如#video)发送机器人,并且该视频实际上是视频附件,则该机器人会在该频道中进行回复并复制视频附件到另一个频道。如果是短信,则漫游器只会删除该短信。 我目前没有代码,因为我不知道大声笑。

当前代码:

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:请求实体太大

1 个答案:

答案 0 :(得分:0)

我认为这可以满足您的需求。

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
    }
});