【发布时间】: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