errbotio / err-backend-discord

Backend for Discord for Errbot
GNU General Public License v3.0
23 stars 22 forks source link

Fix DiscordRoom with no ID #64

Closed inakiuy closed 8 months ago

inakiuy commented 8 months ago

This fix make the bot work when I issue !help on my discord server.

I started with version 4.0.0 from pip but had the same error ass issue #59

ERROR discord.client Ignoring exception in on_ready Traceback (most recent call last): File "/root/errbot-venv/lib/python3.10/site-packages/discord/client.py", line 409, in _run_event await coro(*args, **kwargs) File "/root/errbot-venv/lib/python3.10/site-packages/errbot/backends/err-backend-discord.py", line 90, in on_ready self.bot_identifier = DiscordPerson(DiscordBackend.client.user.id) File "/root/errbot-venv/lib/python3.10/site-packages/errbot/backends/discordlib/person.py", line 56, in init raise ValueError(f"Invalid Discord user id {type(user_id)} {user_id}.") ValueError: Invalid Discord user id <class 'int'> XXXXXXXXXXXXXXXXXXX

Found @nzlosh reference and tried that branch.

Now error changed.

ERROR discord.client Ignoring exception in on_message Traceback (most recent call last): File "/root/errbot-venv/lib/python3.10/site-packages/discord/client.py", line 409, in _run_event await coro(*args, **kwargs) File "/root/errbot-venv/lib/python3.10/site-packages/errbot/backends/err-backend-discord.py", line 99, in on_message if self.process_message(err_msg): File "/root/errbot-venv/lib/python3.10/site-packages/errbot/core.py", line 270, in process_message raise Exception( Exception: msg.frm not an Identifier as it misses the "person" property. Class of frm : <class 'discordlib.room.DiscordRoomOccupant'>.

I dont understand every pice of code and never worked with discord.py but looking at errors and putting some logs, I seemed to me that _channel_id was not set.

Added "channel.id" in the from_id class method and I worked.

I dont know if it breaks something else.

Just wanted to post this so others can validate and maybe explain why this works 😄

DEBUG errbot.plugins.VersionChe Latest Errbot version is: 6.1.9 DEBUG errbot.plugins.VersionChe Installed Errbot version is: 6.1.9

image

nzlosh commented 8 months ago

LGTM. Thanks for the fix!