Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrectly Throwing Error for Channel Deletion #10074

Open
3 tasks done
mkaulfers opened this issue Jan 10, 2025 · 2 comments
Open
3 tasks done

Incorrectly Throwing Error for Channel Deletion #10074

mkaulfers opened this issue Jan 10, 2025 · 2 comments
Labels
unconfirmed bug A bug report that needs triaging

Comments

@mkaulfers
Copy link

Summary

Incorrectly Throwing Error for Channel Deletion

Reproduction Steps

Copy reproducible code below, to a Cog listener. Replace the constants with your own, then join the channel. When you leave the channel, observe that an exception is thrown.

Minimal Reproducible Code

@commands.Cog.listener()
    async def on_voice_state_update(self, member: discord.Member, before, after):
        joined_channel_name = after.channel.name if after.channel else None
        
        try: 
            if before.channel and before.channel.id in self.created_channels:
                if len(before.channel.members) == 0:
                    await before.channel.delete()
                    del self.created_channels[before.channel.id]
                    return
            
            if joined_channel_name == CREATE_VC_CHANNEL_NAME:
                new_channel = await member.guild.create_voice_channel(
                    name=f"{member.display_name}'s Channel",
                    category=after.channel.category,
                    position=after.channel.position + 1
                )
            
                await member.move_to(new_channel)
                self.created_channels[new_channel.id] = new_channel

                view = discord.ui.View()
                view.add_item(ManageChannelButton())

                await new_channel.send(
                    f"Welcome to your new channel, {member.mention}!",
                    view=view
                )
                
        except Exception as e:
            print(f"[create_vc] An error occurred: {e}")

Expected Results

I expected it to delete the channel, when no members are connected, without throwing an error.

Actual Results

Channel was deleted, error thrown.

Intents

All

System Information

  • Python v3.11.3-final
  • discord.py v2.4.0-final
  • aiohttp v3.11.11
  • system info: Windows 10 10.0.22631

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

@mkaulfers mkaulfers added the unconfirmed bug A bug report that needs triaging label Jan 10, 2025
@pythonmcpi
Copy link
Contributor

pythonmcpi commented Jan 10, 2025

[x] I have shown the entire traceback, if possible.

Please actually include the traceback before checking this checkbox. Thanks!

@SystemNatalie
Copy link

SystemNatalie commented Jan 27, 2025

Unable to reproduce using the following code:

@commands.Cog.listener()
    async def on_voice_state_update(self, member: discord.Member, before, after):
        joined_channel_name = after.channel.name if after.channel else None

        try:
            if before.channel and before.channel.id in self.created_channels:
                if len(before.channel.members) == 0:
                    await before.channel.delete()
                    del self.created_channels[before.channel.id]
                    return

            if joined_channel_name == "vctest":
                new_channel = await member.guild.create_voice_channel(
                    name=f"{member.display_name}'s Channel",
                    category=after.channel.category,
                    position=after.channel.position + 1
                )

                await member.move_to(new_channel)
                self.created_channels[new_channel.id] = new_channel

                #view = discord.ui.View()
                #view.add_item(ManageChannelButton())

                await new_channel.send(
                    f"Welcome to your new channel, {member.mention}!")#,
                    #view=view
                #)

        except Exception as e:
            print(f"[create_vc] An error occurred: {e}")

I suspect you have an issue in your view. As @pythonmcpi said, please include the traceback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

No branches or pull requests

3 participants