简体   繁体   English

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

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

I am trying to make the bot in a certain channel if a video attachment is sent in for example #video and if it is actually a video attachment, the bot will reply in that channel something and copy the video attachment to another channel.如果发送视频附件,例如#video ,并且如果它实际上是视频附件,我正在尝试在某个频道中制作机器人,如果它实际上是视频附件,机器人将在该频道中回复某些内容并将视频附件复制到另一个频道。 If it's a text message, the bot will just delete the text message.如果是短信,机器人只会删除短信。 I currently have no code because I have no idea lol.Ž我目前没有代码,因为我不知道 lol.Ž

Current code:当前代码:

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

I get an error: DiscordAPIError: Request entity too large我收到一个错误:DiscordAPIError:请求实体太大

I think this does what you want.我认为这可以满足您的要求。

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