我试图通过一个不和谐的斜杠命令交互获得一个图像附件,所以我可以将一个被操纵的版本发送回用户,但我似乎无法做到这一点。
交互本身是可以通过的,但是"image"选项的对象只是{name: 'image', type: undefined, value: '972518871573602374'}。我觉得奇怪的是,尽管我清楚地使用了.addAttachmentOption()方法,但类型还是没有定义。
这是我的命令生成器:
new SlashCommandBuilder()
.setName("dither")
.setDescription("Apply a dithering effect to an image")
.addAttachmentOption((option)=> option
.setRequired(true)
.setName("image")
.setDescription("The image to dither"))
.addNumberOption((option)=> option
.setRequired(false)
.setName("intensity")
.setDescription(`% of dithering to apply (${intensityDefault}% by default)`))
.toJSON()我认为URL或其他东西可能在交互对象的其他地方,但我找不到任何与附件相关的内容。我在文档中也找不到任何关于交互附件的信息,所以我想在这里尝试一下。它只是一个未实现的特性吗?但为什么会有一个方法呢?
我也不确定value属性代表什么。我以为它可以是附件ID,但是即使我想自己重新创建附件URL,我仍然需要知道文件名。
发布于 2022-05-21 15:29:44
根据https://discordjs.guide/interactions/slash-commands.html#parsing-options的说法:
const attachment = interaction.options.getAttachment("image")
const name = attachment.name
const url = attachment.url
const proxyURL = attachment.proxyURL请注意,在上面的示例中,我使用了image,因为这是附件的名称- .setName("image")。
发布于 2022-07-24 03:08:35
这是我的代码,它能工作
new SlashCommandBuilder()
.setName('test')
.setDescription('Test Command!')
.addAttachmentOption(option => option
.setName('attach')
.setDescription('Attachment File')
.setRequired(true)),
async execute(interaction, client) {
const message = await interaction.deferReply({
fetchReply: true
});
const user = message.author
const file = interaction.options.getAttachment('attach')
const emb = new MessageEmbed()
.setAuthor(user.username, user.displayAvatarURL(true))
.setTitle('Embed Message /w attachment')
.setDescription('Uploading attachment...')
.setThumbnail(message.guild.iconURL(true))
.setTimestamp()
.setImage(file.url)
.setFooter('Successfully', user.displayAvatarURL(true))
console.log(emb)
await interaction.editReply({ embeds: [emb] });```https://stackoverflow.com/questions/72154232
复制相似问题