-
-
Notifications
You must be signed in to change notification settings - Fork 482
Description
Summary
title
Reproduction Steps
see mrc
Minimal Reproducible Code
import discord
import os
from dotenv import load_dotenv
load_dotenv()
bot = discord.Bot(intents=discord.Intents.all())
@bot.slash_command(name="test", description="Test command")
@discord.option(name="option", description="Test option", channel_types=[discord.ChannelType.text], required=False)
async def test(ctx: discord.ApplicationContext, option: discord.TextChannel | None = None):
if option:
await ctx.respond(f"Test command with channel: {option.name}")
else:
await ctx.respond("Test command without a channel.")
bot.run(os.getenv("TOKEN"))
Expected Results
No error
Actual Results
Traceback (most recent call last):
File "/home/akos/amox/tests/a.py", line 10, in
@discord.option(name="option", description="Test option", channel_types=[discord.ChannelType.text], required=False)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/akos/amox/.venv/lib/python3.13/site-packages/discord/commands/options.py", line 438, in decorator
func.annotations[resolved_name] = Option(itype, name=name, **kwargs)
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/akos/amox/.venv/lib/python3.13/site-packages/discord/commands/options.py", line 243, in init
raise exc
File "/home/akos/amox/.venv/lib/python3.13/site-packages/discord/commands/options.py", line 238, in init
self.input_type = SlashCommandOptionType.from_datatype(input_type)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/home/akos/amox/.venv/lib/python3.13/site-packages/discord/enums.py", line 810, in from_datatype
return cls.from_datatype(datatype.args) # type: ignore
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/home/akos/amox/.venv/lib/python3.13/site-packages/discord/enums.py", line 795, in from_datatype
datatypes = [cls.from_datatype(op) for op in datatype]
~~~~~~~~~~~~~~~~~^^^^
File "/home/akos/amox/.venv/lib/python3.13/site-packages/discord/enums.py", line 852, in from_datatype
raise TypeError(
^^^^^^^^^^^^^^^^
f"Invalid class {datatype} used as an input type for an Option"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
) # TODO: Improve the error message
^
TypeError: Invalid class <class 'NoneType'> used as an input type for an Option
Intents
any
System Information
- Python v3.13.2-final
- py-cord v2.6.1-final (master too)
- aiohttp v3.12.13
- system info: Linux 5.15.0-144-generic Add Discord Developer Portal link #157-Ubuntu SMP Mon Jun 16 07:33:10 UTC 2025
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
Additional Context
https://discord.com/channels/881207955029110855/1132206148309749830/1398342377042612376