-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
as designedThis feature is working as intendedThis feature is working as intended
Description
Summary
When defining commands with the @discord.app_commands.command()
decorator with methods in a cog decorated with @staticmethod
, a TypeError
is raised with message "command function must be coroutine function."
Reproduction Steps
- Create a cog
- Define an app command with a function signature such as
@discord.app_commands.command()
@staticmethod
async def my_command(interaction: discord.Interaction):
# ...
- Add code to load the cog
- Get
TypeError: command must be coroutine function
when running (though no type errors are reported by Pylance).
Such an example is attached in images (and see below):
Minimal Reproducible Code
import discord
from discord.ext import commands
class MyCog(commands.Cog):
@discord.app_commands.command()
@staticmethod
async def my_command(interaction: discord.Interaction):
await interaction.response.send("You will never see this")
class MyBot(commands.Bot):
async def setup_hook(self):
await self.add_cog(MyCog())
bot = MyBot("!", intents=discord.Intents.default())
bot.run("TOKEN")
Expected Results
A command is registered, as usual.
Actual Results
Traceback (most recent call last):
File "/app/minrepo.py", line 5, in <module>
class MyCog(commands.Cog):
File "/app/minrepo.py", line 6, in MyCog
@discord.app_commands.command()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/venv/lib/python3.11/site-packages/discord/app_commands/commands.py", line 1965, in decorator
raise TypeError('command function must be a coroutine function')
TypeError: command function must be a coroutine function
Intents
Just the defaults (irrelevant)
System Information
- Python v3.11.5-final
- discord.py v2.3.2-final
- aiohttp v3.8.5
- system info: Linux 5.10.0-23-amd64 #1 SMP Debian 5.10.179-1 (2023-05-12)
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
No response
Metadata
Metadata
Assignees
Labels
as designedThis feature is working as intendedThis feature is working as intended