discord-api-docs icon indicating copy to clipboard operation
discord-api-docs copied to clipboard

attaching a file as an attachment option gives the error "This option is required. Specify a value" as if no file was attached

Open eeropomell opened this issue 7 months ago • 15 comments

Description

I have a discord bot (discord.js) with a slash command that takes in an attachment option. Sometimes when I try to use the command and attach a file, the discord app acts as if no file has been attached.

The slash command is as simple as:

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
	data: new SlashCommandBuilder()
		.setName('sdbattle_submit')
		.setDescription('submit!')
        .addAttachmentOption(option =>
             option.setName('file')
             .setDescription('The file to upload')
             .setRequired(true)),
	async execute(interaction) {
	},
};

Intents:

const client = new Client({ intents: [
    GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers] });

Interaction handling:

client.on(Events.InteractionCreate, async interaction => {
	if (!interaction.isChatInputCommand()) return;

	const command = interaction.client.commands.get(interaction.commandName);

	if (!command) {
		console.error(`No command matching ${interaction.commandName} was found.`);
		return;
	}

	try {
		await command.execute(interaction);
	} catch (error) {
		console.error(error);
		if (interaction.replied || interaction.deferred) {
			await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
		} else {
			await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
		}
	}
});

Versions

  • Ubuntu 22.04 firefox
  • stable 256231 (96a39c5)
  • Node v21.5

Steps to Reproduce

Steps to reproduce:

  1. Create a Discordjs bot with a slash command builder that takes an attachment as an option: .addAttachmentOption(option => option.setName('image').setDescription('The image file').setRequired(true))

  2. Call the slash command and try to paste a file into the image field

  3. Upon trying to send the message the attachment field will light up red and you will get an error saying "This option is required. Specify a value"

Expected Behavior

When selecting a file as an option to the slash command, the app should recognize that a file has been attached. Upon trying to call the command, the command should be sent to the bot.

Current Behavior

When trying to use a slash command that takes in an attachment option, the following bugs can occur:

  1. dragging and dropping a file into the selection doesn't attach it
  2. selecting a file from the file explorer attaches it, but when trying to send the command, the discord app acts as if no file has been attached. Gives the error "This option is required. Specify a value"

Screenshots/Videos

https://github.com/discord/discord-api-docs/assets/97628152/98fcaee9-5953-40d6-be6c-a6fc7af9c58d

Client and System Information

  • Ubuntu 22.04 firefox
  • discord.js 14.14.1
  • Node v21.05
  • stable 256231 (96a39c5)

eeropomell avatar Dec 29 '23 15:12 eeropomell

I couldn't repro with the repro steps you provided. Can you provide additional repro steps to help us narrow this down?

appellation avatar Jan 02 '24 18:01 appellation

Similar but not quite exact behavior for me with python 3.10 and pycord 2.4.1 using discord client Stable 256231 (96a39c5) Host 1.0.9028 x86 (41936) Windows 10 64-Bit (10.0.19045).

About 2 weeks ago using ctrl + v would work to paste images as attachments, but now it is being blocked as showcased by KuJu on discord api server.

Dragging the file in from a chrome browser window still works or selecting the file from explorer.

bandicam-2023-12-26-09-25-14-580

Code example that doesn't allow ctrl+v:

import discord
bot = discord.Bot(debug_guilds=[305380209366925312])

@bot.event
async def on_ready():
    print(f"{bot.user} is online!")


@bot.slash_command(name="profile")
async def profile(ctx, attachment : discord.Attachment):
    await ctx.respond("yo")

bot.run(token)

homer2011 avatar Jan 04 '24 07:01 homer2011

Description

I have a discord bot (discord.js) with a slash command that takes in an attachment option. Sometimes when I try to use the command and attach a file, the discord app acts as if no file has been attached.

The slash command is as simple as:

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
	data: new SlashCommandBuilder()
		.setName('sdbattle_submit')
		.setDescription('submit!')
        .addAttachmentOption(option =>
             option.setName('file')
             .setDescription('The file to upload')
             .setRequired(true)),
	async execute(interaction) {
	},
};

Intents:

const client = new Client({ intents: [
    GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers] });

Interaction handling:

client.on(Events.InteractionCreate, async interaction => {
	if (!interaction.isChatInputCommand()) return;

	const command = interaction.client.commands.get(interaction.commandName);

	if (!command) {
		console.error(`No command matching ${interaction.commandName} was found.`);
		return;
	}

	try {
		await command.execute(interaction);
	} catch (error) {
		console.error(error);
		if (interaction.replied || interaction.deferred) {
			await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
		} else {
			await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
		}
	}
});

Versions

  • Ubuntu 22.04 firefox
  • stable 256231 (96a39c5)
  • Node v21.5

Steps to Reproduce

Steps to reproduce:

  1. Create a Discordjs bot with a slash command builder that takes an attachment as an option: .addAttachmentOption(option => option.setName('image').setDescription('The image file').setRequired(true))
  2. Call the slash command and try to paste a file into the image field
  3. Upon trying to send the message the attachment field will light up red and you will get an error saying "This option is required. Specify a value"

Expected Behavior

When selecting a file as an option to the slash command, the app should recognize that a file has been attached. Upon trying to call the command, the command should be sent to the bot.

Current Behavior

When trying to use a slash command that takes in an attachment option, the following bugs can occur:

  1. dragging and dropping a file into the selection doesn't attach it
  2. selecting a file from the file explorer attaches it, but when trying to send the command, the discord app acts as if no file has been attached. Gives the error "This option is required. Specify a value"

Screenshots/Videos

83ed85ad19def89300281443e540acab.mp4

Client and System Information

  • Ubuntu 22.04 firefox
  • discord.js 14.14.1
  • Node v21.05
  • stable 256231 (96a39c5)

I have similar issue. Funny thing is that Android app still works normally and adding attachments works. I think its an issue with web and desktop clients.

greedyj4ck avatar Jan 08 '24 00:01 greedyj4ck

A similar issue happens for me too. It was the same for my bot as for OP, but a later update fixed it. But with the fix came a bug when trying to attach an image using CTRL+V. Dragging an image into the image field otherwise works, just not from the clipboard, but it's still an inconvenience. Issue has been ongoing for over a week, happens on two of our household computers:

https://github.com/discord/discord-api-docs/assets/141376657/26d9a58b-5cc2-445b-b3bc-8477049a4183

Using the following versions: image

Also on a bot written with Discordjs, contacted their developers, they said that it's a Discord sided problem

Khajetav avatar Jan 08 '24 09:01 Khajetav

Please keep this issue discussion related to the original post. If you're experiencing a different issue, feel free to open a new issue.

appellation avatar Jan 08 '24 16:01 appellation

I couldn't repro with the repro steps you provided. Can you provide additional repro steps to help us narrow this down?

Issue seems to be happening only on forum channel threads (did not checked standard threads). Attached two videos showing the same exact command executed on threads and normal channel.

Client and System Information

Issue persist in web and desktop client.

Electron 22.3.26
Chromium 108.0.5359.215
Host 1.0.9030 x86 (42484)
Windows 10 64-Bit (10.0.22621)

No issue when using the slash command (both forum channel thread or standard channel) on Android client (tested on 210.10 app version)

Steps to reproduce:

  1. Create a command using SlashCommandBuilder and addAttachmentOption:
.addSubcommand((subcommand) =>
      subcommand
        .setName("banner")
        .setDescription("Edytuj banner")
        .addAttachmentOption((option) =>
          option
            .setName("banner")
            .setDescription(
              "Nowy banner twojej kampanii w formacie graficznym webp, png, jpeg (zaleca się korzystać z ratio 3:2)"
            )
            .setRequired(true)
        )
    )
  1. Call the slash command (on forum thread type channel) and select attachment file.
  2. Upon trying to send the message the attachment field will light up red and you will get an error saying "This option is required. Specify a value"

Videos and screenshots

Using command on forum threads

https://github.com/discord/discord-api-docs/assets/33233389/ad49510c-f07a-4b45-94ca-83b788e83d1c

Using command on normal channel

https://github.com/discord/discord-api-docs/assets/33233389/e2fe8f33-9211-409c-a36d-05c1393ebef8

greedyj4ck avatar Jan 11 '24 22:01 greedyj4ck

@appellation

I was able to pinpoint the exact condition when the error occurs - when a post is displayed in split view - forum on left, post content on right. When you display a post in a full view, slash command is working properly (bot was offline during the recording, but the client launched the slash command).

https://github.com/discord/discord-api-docs/assets/33233389/3c353fb0-263b-4f5d-9938-eb8d6f0cb812

greedyj4ck avatar Jan 16 '24 20:01 greedyj4ck

Thanks for the detailed repro steps! I was able to repro; I'll look into a fix.

appellation avatar Jan 16 '24 20:01 appellation

Any luck with the issue ?

greedyj4ck avatar Feb 05 '24 22:02 greedyj4ck

I just ran into this as well. Same command works fine in public channel but not in a thread.

One additional data point if it helps... I tried removing the setRequired(true) from my command to see if that would help. It still doesn't accept the file upload but it shows a different error. Instead of This option is required. Specify a value it now says Not a valid value.

Screenshot 2024-02-19 at 1 02 55 PM

Edit to add: Discord desktop client 0.0.294 macOS 13.4.1

aricallen avatar Feb 19 '24 21:02 aricallen

SOLVED....

i had solved it in Python:

import discord from discord.ext import commands

intents = discord.Intents.default() intents.message_content = True # Enable message content intent

bot = commands.Bot(command_prefix='!', intents=intents)

BASICALLY we are missing intents.message_content = True # Enable message content intent

then it will work

thanks me LATER ....

HaiderImtiaz avatar Apr 08 '24 15:04 HaiderImtiaz

Any luck with the issue ?

FIXED

HaiderImtiaz avatar Apr 08 '24 15:04 HaiderImtiaz

Any luck with the issue ?

FIXED check my reply

HaiderImtiaz avatar Apr 08 '24 15:04 HaiderImtiaz

Any luck with the issue ?

FIXED check my reply

Already using MessageContent intents, without it commands doesn't work at all.

// Edit: please share a video with your command successfully processing attachment while executed on forum thread in split view.

greedyj4ck avatar Apr 08 '24 15:04 greedyj4ck

i am seeing the same issue. adding MessageContent intent did not help.

tsjnsn avatar May 07 '24 21:05 tsjnsn