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

Misleading exception when creating a group with one user #703

Closed
3 tasks done
Sitois opened this issue Jun 14, 2024 · 4 comments
Closed
3 tasks done

Misleading exception when creating a group with one user #703

Sitois opened this issue Jun 14, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@Sitois
Copy link

Sitois commented Jun 14, 2024

Summary

Trying to create a group

Reproduction Steps

With this code:

random_user = random.choice(bot.friends)
panel = await bot.create_group(random_user.user)
await panel.remove_recipients(random_user.user)
await panel.edit(name="Nuclear Panel")
await panel.send("hi")

Code

Traceback (most recent call last):
  File "c:\Users\user\Desktop\Nuclear-V2\discord\client.py", line 637, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\user\Desktop\Nuclear-V2\main.py", line 248, in on_ready
    panel = await bot.create_group(random_user.user)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\Desktop\Nuclear-V2\discord\client.py", line 3171, in create_group
    return GroupChannel(me=self.user, data=data, state=state)  # type: ignore # user is always present when logged in
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\Desktop\Nuclear-V2\discord\channel.py", line 3916, in __init__
    self._update(data)
  File "c:\Users\user\Desktop\Nuclear-V2\discord\channel.py", line 3919, in _update
    self.owner_id: int = int(data['owner_id'])
                             ~~~~^^^^^^^^^^^^
KeyError: 'owner_id'

Expected Results

Its supposed to create a group

Actual Results

An error occures

System Information

  • Python v3.11.4-final
  • discord.py-self v2.1.0-alpha
    • discord.py-self metadata: v2.1.0a4850+g9f782b60
  • aiohttp v3.9.5
  • system info: Windows 10 10.0.22631 (btw I'm using Windows 11 ???)

Checklist

  • I have searched the open issues for duplicates.
  • I have shared the entire traceback.
  • I am using a user token (and it isn't visible in the code).

Additional Information

No response

@Sitois Sitois added the unconfirmed bug Unconfirmed bug label Jun 14, 2024
@dolfies
Copy link
Owner

dolfies commented Jun 14, 2024

You cannot create a group with one user. This is just creating a DM channel while the library thinks it's a group channel, causing this error. I'll make it throw a more descriptive error.

@Sitois
Copy link
Author

Sitois commented Jun 14, 2024

You cannot create a group with one user. This is just creating a DM channel while the library thinks it's a group channel, causing this error. I'll make it throw a more descriptive error.

I'll try that later, thanks!

@dolfies dolfies added bug Something isn't working and removed unconfirmed bug Unconfirmed bug labels Jun 14, 2024
@dolfies dolfies changed the title Error while trying to create a group Misleading exception when creating a group with one user Jun 14, 2024
@dolfies
Copy link
Owner

dolfies commented Jun 14, 2024

Just fixed in the latest commit. Looking at your code, it seems you're removing the single recipient anyway. If you want an empty group, you can just do that:

panel = await bot.create_group()
await panel.edit(name="Nuclear Panel")
await panel.send("hi")

@dolfies dolfies closed this as completed Jun 14, 2024
@Sitois
Copy link
Author

Sitois commented Jun 14, 2024

It works great.
A big thank for this amazing library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants