dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
707 stars 162 forks source link

Misleading exception when creating a group with one user #703

Closed Sitois closed 4 months ago

Sitois commented 4 months ago

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

Checklist

Additional Information

No response

dolfies commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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")
Sitois commented 4 months ago

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