Summary
On a SlashCommandGroup with integration_types without contexts, reading its .guild_only property raises a TypeError
Reproduction Steps
- Create a
SlashCommandGroup (or SlashCommand) and provide the integration_types argument.
- Explicitly omit the
contexts argument (or leave it as None).
- Attempt to access the
.guild_only property on the instantiated command group or command.
- Observe the resulting
TypeError exception.
Minimal Reproducible Code
import discord
bot = discord.Bot()
# Define a group with integration_types but NO contexts
music_group = discord.SlashCommandGroup(
name="music",
description="Music commands",
integration_types={discord.IntegrationType.guild_install}
)
# Attempting to read guild_only triggers the bug
print(music_group.guild_only)
Expected Results
The guild_only property should safely return a boolean value (e.g., False or evaluate based solely on integration_types) without crashing. Pycord's internal property logic should handle cases where self.contexts is None.
Actual Results
A TypeError is thrown immediately upon property access:
/Users/mx/Desktop//test.py:13: DeprecationWarning: guild_only is deprecated since version 2.6, consider using contexts instead.
print(music_group.guild_only)
Traceback (most recent call last):
File "/Users/mx/Desktop/test.py", line 13, in <module>
print(music_group.guild_only)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/mx/Desktop/.venv/lib/python3.14/site-packages/discord/commands/core.py", line 1352, in guild_only
return InteractionContextType.guild in self.contexts and len(self.contexts) == 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not a container or iterable
Intents
discord.Intents.default() (Note: Intents are irrelevant to this specific internal attribute/property bug, as it happens prior to bot connection.)
System Information
- OS: System agnostic (Windows / Linux / macOS)
- Python version: v3.10+
- Pycord version: v2.6.0+ (Including v2.8.0rc1)
Checklist
Additional Context
This internal bug frequently breaks automated help cog generators or custom command tree iterators. When these scripts loop through bot.walk_application_commands() and evaluate command.guild_only to filter out non-guild commands for their dynamic UI, the loop crashes and skips commands entirely. A simple internal fix in Pycord's guild_only getter property would be to use a safety check, such as: if self.contexts is not None and InteractionContextType.guild in self.contexts.
I'm aware this method is deprecated, but I feel like this bug is still worth mentioning for people who still use guild_only.
The code that causes this problem should be:
|
return InteractionContextType.guild in self.contexts and len(self.contexts) == 1 |
Summary
On a
SlashCommandGroupwithintegration_typeswithoutcontexts, reading its.guild_onlyproperty raises a TypeErrorReproduction Steps
SlashCommandGroup(orSlashCommand) and provide theintegration_typesargument.contextsargument (or leave it asNone)..guild_onlyproperty on the instantiated command group or command.TypeErrorexception.Minimal Reproducible Code
Expected Results
The
guild_onlyproperty should safely return a boolean value (e.g.,Falseor evaluate based solely onintegration_types) without crashing. Pycord's internal property logic should handle cases whereself.contextsisNone.Actual Results
A
TypeErroris thrown immediately upon property access:Intents
discord.Intents.default()(Note: Intents are irrelevant to this specific internal attribute/property bug, as it happens prior to bot connection.)System Information
Checklist
Additional Context
This internal bug frequently breaks automated help cog generators or custom command tree iterators. When these scripts loop through
bot.walk_application_commands()and evaluatecommand.guild_onlyto filter out non-guild commands for their dynamic UI, the loop crashes and skips commands entirely. A simple internal fix in Pycord'sguild_onlygetter property would be to use a safety check, such as:if self.contexts is not None and InteractionContextType.guild in self.contexts.I'm aware this method is deprecated, but I feel like this bug is still worth mentioning for people who still use
guild_only.The code that causes this problem should be:
pycord/discord/commands/core.py
Line 1348 in 71c48a2