Skip to content

discord.utils.get TypeError on Voice Channel Search #1483

Closed
@Tiffinini

Description

@Tiffinini

Summary

Using utils.get to fetch a voice channel will fail with a TypeError if a command is executed that contains a VoiceChannel as an option.

Reproduction Steps

  1. Execute a slash command that has an option parameter of type discord.VoiceChannel.

  2. Attempt to run any code that uses utils.get to fetch a VoiceChannel afterwards. It will fail, and any subsequent attempts to use utils.get to fetch a VoiceChannel will fail too.

Minimal Reproducible Code

I reproduced this using the following two bot commands in a bot implementation. These commands were created in a cog:

    @slash_command(name="bug-test", guild_ids=globals.COMMAND_GUILD_ID_REGISTER_LIST, default_permissions=True)
    async def bug_test(self, ctx: discord.ApplicationContext) -> None:
        async def test_task():
            while True:
                channel_name = "Intro 1"
                channel = utils.get(ctx.guild.voice_channels, name=channel_name)
                
                print(f"Channel is: {channel}")
                               
                await asyncio.sleep(1)
                
        self.bot.loop.create_task(test_task())
        
        await ctx.respond("Okay", ephemeral=True)
    @slash_command(name="bug-test-two", guild_ids=globals.COMMAND_GUILD_ID_REGISTER_LIST, default_permissions=True)
    async def bug_test2(self, ctx: discord.ApplicationContext, random_voice_channel: discord.VoiceChannel) -> None:
        await ctx.respond(f"Channel is: {random_voice_channel}", ephemeral=True)

Use /bug-test, which will continually show a fetched channel, then at any point use /bug-test-two. The loop in the first command's task will then fail with a traceback, as will any subsequent attempts anywhere to use utils.get() to fetch a VoiceChannel.

Expected Results

The utils.get() method continues to function after commands with VoiceChannel as an option are used.

Actual Results

07/10/2022 04:24:11 PM - asyncio - ERROR -> Task exception was never retrieved
future: <Task finished name='Task-37' coro=<WaitlistQueue.bug_test.<locals>.test_task() done, defined at C:\Users\Tiffany\dev\bot\cogs\av_fleet_queue\fleet_queue_main.py:736> exception=TypeError("'<' not supported between instances of 'NoneType' and 'int'")>
Traceback (most recent call last):
  File "C:\Users\Tiffany\dev\bot\cogs\av_fleet_queue\fleet_queue_main.py", line 739, in test_task
    channel = utils.get(ctx.guild.voice_channels, name=channel_name)
  File "c:\Users\Tiffany\dev\bot\venv\lib\site-packages\discord\guild.py", line 620, in voice_channels
    r.sort(key=lambda c: (c.position, c.id))
TypeError: '<' not supported between instances of 'NoneType' and 'int'

Intents

All

System Information

  • Python v3.9.2-final
  • py-cord v2.0.0-final
  • aiohttp v3.8.1
  • system info: Windows 8.1 6.3.9600

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

This error did not occur in 2.0.0rc1. This causes the stable release of 2.0.0 to be unsuitable for live deployments for any bot that has any meaningful interaction with voice channels.

It would seem whatever fix was applied to keep cached channel data up to date specifically from slash options completely breaks the cache for VCs.

Metadata

Metadata

Assignees

Labels

unconfirmed bugA bug report that needs triaging

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions