【问题标题】:SlashCommandBuilder option to add file attachment (addAttachmentOption). Is there a way to get the image sent?SlashCommandBuilder 选项添加文件附件(添加附件选项)。有没有办法让图像发送?
【发布时间】:2022-06-16 16:33:03
【问题描述】:

我正在按照 discord 指南 (https://discordjs.guide/#before-you-begin) 制作机器人,并且我能够将所有内容都设置好。但我尝试制作一个斜杠命令,用户将图像附加到聊天输入框,并且图像由指定频道中的机器人发送。问题是,我找不到从输入中获取图像的方法,这里是如何工作的:

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('diario')
        .setDescription('Escreve uma notícia!')
                .setDefaultPermission(false)
        .addStringOption(option => option.setName('titulo').setDescription('Escreva seu título!')
        .setRequired(true))
        .addStringOption(option => option.setName('descrição').setDescription('Descreva brevemente.')
        .setRequired(true))
        .addAttachmentOption(option => option.setName('imagem').setDescription("Anexe uma imagem ilustrativa")
        .setRequired(true)),
    async execute(interaction) {
        const action = await interaction;
        const exampleEmbed = new MessageEmbed()
    .setColor('#0099ff')
    .setTitle(action.options.getString('titulo'))
    .setDescription(action.options.getString('descrição'))
        .setImage('')
        action
        .client
        .channels
        .cache
        .find(channel => channel.name == "jornal")
        .send({ embeds: [exampleEmbed] })
        action.reply({ content: 'Sua notícia foi publicada!', ephemeral: false });
        action.deleteReply();
},
};

我可以通过命令“action.options.getString()”获取字符串值 但是无法获取我发送的图像。我可以使用“action.options.get()”来获取附件名称如下的对象 { name: "imagem", type: undefined, value: 123456789 }。

有办法吗?

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    您可以从命令交互中接收附件 .options.getAttachment()

    【讨论】:

      猜你喜欢
      • 2018-12-23
      • 1970-01-01
      • 1970-01-01
      • 2016-03-31
      • 2015-04-19
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      相关资源
      最近更新 更多