errbotio / err-backend-discord

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

Possible Bug #56

Closed GrantBirki closed 1 year ago

GrantBirki commented 1 year ago

https://github.com/errbotio/err-backend-discord/blob/82b55570fefe7fad8a82f891302686e5201e3b55/src/err-backend-discord/err-backend-discord.py#LL413C15-L413C15

Instead of:

return DiscordPerson(user_id=member.id)

Should it be something like(?):

return DiscordPerson(username=user, discriminator=discriminator)
GrantBirki commented 1 year ago

For context, I'm getting errors all over when trying to upgrade my bot like so

self.user_id = member.id

AttributeError: 'NoneType' object has no attribute 'id'
GrantBirki commented 1 year ago

Here is the pull request where I am trying to upgrade: https://github.com/GrantBirki/errbot/pull/152

GrantBirki commented 1 year ago

I use a slightly different adaptation of your code so I can do things like this: https://github.com/GrantBirki/errbot/pull/152/commits/fea9295caef3138d38be71f2b8950f647ccc1230

nzlosh commented 1 year ago

Thank you for raising this issue. It does appear to be a bug. The DiscordPerson class should be able to take a user id or a username + discriminator. In the case of username + discriminator, they will be resolved to the Discord user id. I've created a fix, would you mind trying it from this branch and letting me know if it resolves the issue for you?

GrantBirki commented 1 year ago

Thank you for the quick reply! I tried that branch and still get an error with the member variable. Traceback below

2022-11-14 12:06:26,736 errbot ERROR    discord.client            Ignoring exception in on_ready

Traceback (most recent call last):

  File "/home/errbot/.local/lib/python3.9/site-packages/discord/client.py", line 409, in _run_event

    await coro(*args, **kwargs)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 85, in on_ready

    self.connect_callback()

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 882, in connect_callback

    self.warn_admins(errors)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 436, in build_identifier

    return DiscordPerson(user_id=member.id)

NameError: name 'member' is not defined
GrantBirki commented 1 year ago

And if I swap my code back to this:

return DiscordPerson(username=user, discriminator=discriminator)

I get the following traceback:

2022-11-14 12:07:47,707 errbot ERROR    discord.client            Ignoring exception in on_ready

Traceback (most recent call last):

  File "/home/errbot/.local/lib/python3.9/site-packages/discord/client.py", line 409, in _run_event

    await coro(*args, **kwargs)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 85, in on_ready

    self.connect_callback()

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 882, in connect_callback

    self.warn_admins(errors)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 436, in build_identifier

    return DiscordPerson(username=user, discriminator=discriminator)

  File "/app/backend/err-backend-discord/discordlib/person.py", line 68, in __init__

    self._user_id = member.id

AttributeError: 'NoneType' object has no attribute 'id'
fernand0 commented 1 year ago

Hi,

I'm finding what I think they are similar problems, but with the status command. When I try to get the status. This is (part of) the traceback (with the fix_person branch:

backends/err-backend-discord/src/err-backend-di scord/err-backend-discord.py", line 93, in on_message err_msg.frm = DiscordPerson(msg.author.id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/fernand0/usr/var/err/backends/err-backend-discord/src/err-backend-discord/discordlib/person.py", line 73, in init raise ValueError(f"Failed to get the user {self._user_id}") ValueError: Failed to get the user

And the same error when using the original err-backend-discord.

nzlosh commented 1 year ago

@fernand0 Have you been able to test using the branch mentioned earlier in the thread?

nzlosh commented 1 year ago

OK disregarded my question, I just saw that you'd tried both. I don't think this is the same issue, but I'll take a look at what might be causing this. How do you produce this error? Do you get it when you execute the !whoami command?

GrantBirki commented 1 year ago

@nzlosh Would it be helpful if we hopped into a Discord call to investigate?

fernand0 commented 1 year ago

@nzlosh same problem with !whoami I'm testing the same installation with gitter backend (just in case) and everything works ok.

nzlosh commented 1 year ago

@fernand0 Have you enabled intents for your bot? https://err-backend-discord.readthedocs.io/en/master/configuration.html#id2

fernand0 commented 1 year ago

Not sure about this, but I think this is my case: "Unverified bots and apps will not be impacted by this change and can continue to use message content in their bot development without requesting any Privileged Intent. " Who knows if sometime in the future it will be a service, but for now it is just a bot for personal use.

nzlosh commented 1 year ago

If you have not enable privileged intents for your bot, errbot's discord backend will no longer function.

https://err-backend-discord.readthedocs.io/en/master/user_guide.html#failed-to-lookup-user

nzlosh commented 1 year ago

It's also necessary to enable the intents in the bot configuration https://err-backend-discord.readthedocs.io/en/master/configuration.html#gateway-intents

fernand0 commented 1 year ago

You are true! Now it works.

Sorry for the noise, I was looking at: https://errbot.readthedocs.io/en/latest/user_guide/configuration/discord.html And there there is no information about the bot configuration. If you want, I can volunteer to make a PR with this info for that page.

nzlosh commented 1 year ago

Good spotting! The discord documentation should be removed from the errbot documentation now that it has be separated out into its own site (I'd forgotten to do that). If you are willing to create a PR for the errbot documentation, that would be most appreciated.

nzlosh commented 1 year ago

@GrantBirki I've pushed the latest fixes to my branch, did they resolve the NameError: name 'member' is not defined error?

fernand0 commented 1 year ago

But, which PR do you prefer?

nzlosh commented 1 year ago

One removing discord documentation from errbot documentation please.

fernand0 commented 1 year ago

OK, I'll do my best.

fernand0 commented 1 year ago

Done #1615

GrantBirki commented 1 year ago

@nzlosh I update my message intents and then used all the latest changes from your branch. I now get this error:

These are the full startup logs from my bot

2022-11-17 21:51:48,163 errbot INFO     errbot.bootstrap          Found Storage plugin: Shelf.

2022-11-17 21:51:48,169 errbot INFO     errbot.bootstrap          Found Backend plugin: Discord

2022-11-17 21:51:48,250 errbot WARNING  errbot.core               Message size limit of 10000 exceeds backends maximum message size 2000.  You might experience message delivery issues.

2022-11-17 21:51:48,367 errbot INFO     pynamodb.settings         Override settings for pynamo not available /etc/pynamodb/global_default_settings.py

2022-11-17 21:51:48,367 errbot INFO     pynamodb.settings         Using Default settings value

2022-11-17 21:51:49,385 errbot INFO     errbot-backend-discord    Enabled intents - guilds, bans, emojis, integrations, webhooks, invites, voice_states, guild_messages, dm_messages, guild_reactions, dm_reactions, guild_typing, dm_typing, guild_scheduled_events, auto_moderation, auto_moderation_configuration, auto_moderation_execution

2022-11-17 21:51:49,386 errbot INFO     errbot-backend-discord    Disabled intents - members, presences, message_content

2022-11-17 21:51:49,386 errbot INFO     discord.client            logging in using static token

2022-11-17 21:51:50,357 errbot INFO     discord.gateway           Shard ID None has connected to Gateway (Session ID: 10dc297e3063ef1e3d435e97614d808c).

2022-11-17 21:51:52,400 errbot INFO     errbot.core               Activate internal commands

2022-11-17 21:51:52,400 errbot INFO     errbot.plugin_manager     Activate bot plugins...

2022-11-17 21:51:52,401 errbot INFO     errbot.plugin_manager     Activate plugin: ACLs.

2022-11-17 21:51:52,406 errbot INFO     errbot.core_plugins.wsview Checking ACLS for webhooks

2022-11-17 21:51:52,406 errbot INFO     errbot.plugin_manager     Activate plugin: Health.

2022-11-17 21:51:52,409 errbot INFO     errbot.core_plugins.wsview Checking Health for webhooks

2022-11-17 21:51:52,409 errbot INFO     errbot.plugin_manager     Activate plugin: Utils.

2022-11-17 21:51:52,411 errbot INFO     errbot.core_plugins.wsview Checking Utils for webhooks

2022-11-17 21:51:52,411 errbot INFO     errbot.plugin_manager     Activate plugin: VersionChecker.

2022-11-17 21:51:52,416 errbot INFO     errbot.core_plugins.wsview Checking VersionChecker for webhooks

2022-11-17 21:51:52,416 errbot INFO     errbot.plugin_manager     Activate plugin: Help.

2022-11-17 21:51:52,418 errbot INFO     errbot.core_plugins.wsview Checking Help for webhooks

2022-11-17 21:51:52,418 errbot INFO     errbot.plugin_manager     Activate plugin: CommandNotFoundFilter.

2022-11-17 21:51:52,420 errbot INFO     errbot.core_plugins.wsview Checking CommandNotFoundFilter for webhooks

2022-11-17 21:51:52,420 errbot INFO     errbot.plugin_manager     Activate plugin: Loud.

2022-11-17 21:51:52,422 errbot INFO     errbot.core_plugins.wsview Checking Load for webhooks

2022-11-17 21:51:52,422 errbot INFO     errbot.plugin_manager     Activate plugin: Wallstreetbets.

2022-11-17 21:51:52,424 errbot INFO     errbot.core_plugins.wsview Checking Wallstreetbets for webhooks

2022-11-17 21:51:52,424 errbot INFO     errbot.plugin_manager     Activate plugin: Down.

2022-11-17 21:51:52,426 errbot INFO     errbot.core_plugins.wsview Checking Down for webhooks

2022-11-17 21:51:52,426 errbot INFO     errbot.plugin_manager     Activate plugin: Qrcode.

2022-11-17 21:51:52,428 errbot INFO     errbot.core_plugins.wsview Checking Qrcode for webhooks

2022-11-17 21:51:52,428 errbot INFO     errbot.plugin_manager     Activate plugin: Crypto.

2022-11-17 21:51:52,429 errbot INFO     errbot.core_plugins.wsview Checking Crypto for webhooks

2022-11-17 21:51:52,430 errbot INFO     errbot.plugin_manager     Activate plugin: Scdl.

2022-11-17 21:51:52,431 errbot INFO     errbot.core_plugins.wsview Checking Scdl for webhooks

2022-11-17 21:51:52,432 errbot INFO     errbot.plugin_manager     Activate plugin: Tts.

2022-11-17 21:51:52,433 errbot INFO     errbot.core_plugins.wsview Checking Tts for webhooks

2022-11-17 21:51:52,434 errbot INFO     errbot.plugin_manager     Activate plugin: Weather.

2022-11-17 21:51:52,435 errbot INFO     errbot.core_plugins.wsview Checking Weather for webhooks

2022-11-17 21:51:52,436 errbot INFO     errbot.plugin_manager     Activate plugin: Example.

2022-11-17 21:51:52,437 errbot INFO     errbot.core_plugins.wsview Checking Example for webhooks

2022-11-17 21:51:52,438 errbot INFO     errbot.plugin_manager     Activate plugin: Confirm.

2022-11-17 21:51:52,439 errbot INFO     errbot.core_plugins.wsview Checking Confirm for webhooks

2022-11-17 21:51:52,440 errbot INFO     errbot.plugin_manager     Activate plugin: Core.

2022-11-17 21:51:52,442 errbot INFO     errbot.core_plugins.wsview Checking Core for webhooks

2022-11-17 21:51:52,442 errbot INFO     errbot.plugin_manager     Activate plugin: Insult.

2022-11-17 21:51:52,444 errbot INFO     errbot.core_plugins.wsview Checking Insult for webhooks

2022-11-17 21:51:52,444 errbot INFO     errbot.plugin_manager     Activate plugin: League.

2022-11-17 21:51:52,447 errbot WARNING  errbot.plugins.League     League cron disabled for local testing

2022-11-17 21:51:52,447 errbot INFO     errbot.core_plugins.wsview Checking League for webhooks

2022-11-17 21:51:52,447 errbot INFO     errbot.plugin_manager     Activate plugin: Facts.

2022-11-17 21:51:52,450 errbot INFO     errbot.core_plugins.wsview Checking Facts for webhooks

2022-11-17 21:51:52,452 errbot INFO     errbot.plugin_manager     Activate plugin: Remember.

2022-11-17 21:51:52,455 errbot INFO     errbot.core_plugins.wsview Checking Remember for webhooks

2022-11-17 21:51:52,456 errbot INFO     errbot.plugin_manager     Activate plugin: Eft.

2022-11-17 21:51:52,459 errbot INFO     errbot.core_plugins.wsview Checking Eft for webhooks

2022-11-17 21:51:52,460 errbot INFO     errbot.plugin_manager     Activate plugin: Sparkle.

2022-11-17 21:51:52,461 errbot INFO     errbot.core_plugins.wsview Checking Sparkle for webhooks

2022-11-17 21:51:52,462 errbot INFO     errbot.plugin_manager     Activate plugin: Boot.

2022-11-17 21:51:52,464 errbot ERROR    errbot.plugin_manager     Plugin Boot failed at activation stage, deactivating it...

2022-11-17 21:51:52,544 errbot ERROR    errbot.plugin_manager     Error loading Boot.

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 557, in activate_plugin

    self._activate_plugin(plugin, plugin_info)

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 510, in _activate_plugin

    plugin.activate()

  File "/app/plugins/boot/boot.py", line 41, in activate

    self.warn_admins(INSTALL_MESSAGE_TEXT)

  File "/usr/local/lib/python3.9/site-packages/errbot/botplugin.py", line 596, in warn_admins

    self._bot.warn_admins(warning)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 419, in build_identifier

    raise ValueError(f"Invalid representation {text}")

ValueError: Invalid representation Birki#0001

2022-11-17 21:51:52,554 errbot ERROR    errbot.plugin_manager     Error loading Boot.

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 557, in activate_plugin

    self._activate_plugin(plugin, plugin_info)

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 510, in _activate_plugin

    plugin.activate()

  File "/app/plugins/boot/boot.py", line 41, in activate

    self.warn_admins(INSTALL_MESSAGE_TEXT)

  File "/usr/local/lib/python3.9/site-packages/errbot/botplugin.py", line 596, in warn_admins

    self._bot.warn_admins(warning)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 419, in build_identifier

    raise ValueError(f"Invalid representation {text}")

ValueError: Invalid representation Birki#0001

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 446, in activate_non_started_plugins

    self.activate_plugin(name)

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 563, in activate_plugin

    raise PluginActivationException(f"{name} failed to start : {e}.")

errbot.plugin_manager.PluginActivationException: Boot failed to start : Invalid representation Birki#0001.

2022-11-17 21:51:52,562 errbot INFO     errbot.plugin_manager     Activate plugin: Ip.

2022-11-17 21:51:52,564 errbot WARNING  errbot.plugins.Ip         GEOLOCATION_KEY not found in environment variables. Disabling the ip plugin.

2022-11-17 21:51:52,565 errbot INFO     errbot.core_plugins.wsview Checking Ip for webhooks

2022-11-17 21:51:52,566 errbot INFO     errbot.plugin_manager     Activate plugin: Play.

2022-11-17 21:51:52,568 errbot INFO     errbot.core_plugins.wsview Checking Play for webhooks

2022-11-17 21:51:52,569 errbot INFO     errbot.plugin_manager     Activate plugin: Covid.

2022-11-17 21:51:52,571 errbot INFO     errbot.core_plugins.wsview Checking Covid for webhooks

2022-11-17 21:51:52,571 errbot INFO     errbot.plugin_manager     Activate flow: PlayFlow

2022-11-17 21:51:52,571 errbot ERROR    discord.client            Ignoring exception in on_ready

Traceback (most recent call last):

  File "/home/errbot/.local/lib/python3.9/site-packages/discord/client.py", line 409, in _run_event

    await coro(*args, **kwargs)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 69, in on_ready

    self.connect_callback()

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 882, in connect_callback

    self.warn_admins(errors)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 419, in build_identifier

    raise ValueError(f"Invalid representation {text}")

ValueError: Invalid representation Birki#0001
nzlosh commented 1 year ago

Is Birki#0001 part of your errbot configuration?

GrantBirki commented 1 year ago

It is indeed

nzlosh commented 1 year ago

Would you mind adding at @ in front of the username please?

GrantBirki commented 1 year ago

My code sends a message to me when the bot starts up. I went ahead and disabled that part of my code and the bot starts but then gets this error when I invoke a command:

2022-11-17 21:56:09,816 errbot ERROR    discord.client            Ignoring exception in on_message

Traceback (most recent call last):

  File "/home/errbot/.local/lib/python3.9/site-packages/discord/client.py", line 409, in _run_event

    await coro(*args, **kwargs)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 97, in on_message

    err_msg.frm = DiscordRoomOccupant(msg.author.id, msg.channel.id)

  File "/app/backend/err-backend-discord/discordlib/room.py", line 250, in __init__

    super().__init__(user_id)

  File "/app/backend/err-backend-discord/discordlib/person.py", line 73, in __init__

    raise ValueError(f"Failed to get the user {self._user_id}")

ValueError: Failed to get the user 107624977066381312

2022-11-17 21:56:12,518 errbot ERROR    discord.client            Ignoring exception in on_message

Traceback (most recent call last):

  File "/home/errbot/.local/lib/python3.9/site-packages/discord/client.py", line 409, in _run_event

    await coro(*args, **kwargs)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 97, in on_message

    err_msg.frm = DiscordRoomOccupant(msg.author.id, msg.channel.id)

  File "/app/backend/err-backend-discord/discordlib/room.py", line 250, in __init__

    super().__init__(user_id)

  File "/app/backend/err-backend-discord/discordlib/person.py", line 73, in __init__

    raise ValueError(f"Failed to get the user {self._user_id}")

ValueError: Failed to get the user 107624977066381312
GrantBirki commented 1 year ago

Let me try adding the @

GrantBirki commented 1 year ago

When I add the @ I get this error on start up

2022-11-17 21:57:57,278 errbot ERROR    errbot.plugin_manager     Error loading Boot.

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 557, in activate_plugin

    self._activate_plugin(plugin, plugin_info)

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 510, in _activate_plugin

    plugin.activate()

  File "/app/plugins/boot/boot.py", line 41, in activate

    self.warn_admins(INSTALL_MESSAGE_TEXT)

  File "/usr/local/lib/python3.9/site-packages/errbot/botplugin.py", line 596, in warn_admins

    self._bot.warn_admins(warning)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 417, in build_identifier

    return DiscordPerson(username=user, discriminator=tag)

  File "/app/backend/err-backend-discord/discordlib/person.py", line 67, in __init__

    self._user_id = member.id

AttributeError: 'NoneType' object has no attribute 'id'

2022-11-17 21:57:57,291 errbot ERROR    errbot.plugin_manager     Error loading Boot.

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 557, in activate_plugin

    self._activate_plugin(plugin, plugin_info)

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 510, in _activate_plugin

    plugin.activate()

  File "/app/plugins/boot/boot.py", line 41, in activate

    self.warn_admins(INSTALL_MESSAGE_TEXT)

  File "/usr/local/lib/python3.9/site-packages/errbot/botplugin.py", line 596, in warn_admins

    self._bot.warn_admins(warning)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 417, in build_identifier

    return DiscordPerson(username=user, discriminator=tag)

  File "/app/backend/err-backend-discord/discordlib/person.py", line 67, in __init__

    self._user_id = member.id

AttributeError: 'NoneType' object has no attribute 'id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 446, in activate_non_started_plugins

    self.activate_plugin(name)

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 563, in activate_plugin

    raise PluginActivationException(f"{name} failed to start : {e}.")

errbot.plugin_manager.PluginActivationException: Boot failed to start : 'NoneType' object has no attribute 'id'.

2022-11-17 21:57:57,299 errbot INFO     errbot.plugin_manager     Activate plugin: Ip.

2022-11-17 21:57:57,301 errbot WARNING  errbot.plugins.Ip         GEOLOCATION_KEY not found in environment variables. Disabling the ip plugin.

2022-11-17 21:57:57,302 errbot INFO     errbot.core_plugins.wsview Checking Ip for webhooks

2022-11-17 21:57:57,302 errbot INFO     errbot.plugin_manager     Activate plugin: Play.

2022-11-17 21:57:57,304 errbot INFO     errbot.core_plugins.wsview Checking Play for webhooks

2022-11-17 21:57:57,305 errbot INFO     errbot.plugin_manager     Activate plugin: Covid.

2022-11-17 21:57:57,307 errbot INFO     errbot.core_plugins.wsview Checking Covid for webhooks

2022-11-17 21:57:57,308 errbot INFO     errbot.plugin_manager     Activate flow: PlayFlow

2022-11-17 21:57:57,308 errbot ERROR    discord.client            Ignoring exception in on_ready

Traceback (most recent call last):

  File "/home/errbot/.local/lib/python3.9/site-packages/discord/client.py", line 409, in _run_event

    await coro(*args, **kwargs)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 69, in on_ready

    self.connect_callback()

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 882, in connect_callback

    self.warn_admins(errors)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 417, in build_identifier

    return DiscordPerson(username=user, discriminator=tag)

  File "/app/backend/err-backend-discord/discordlib/person.py", line 67, in __init__

    self._user_id = member.id

AttributeError: 'NoneType' object has no attribute 'id'
GrantBirki commented 1 year ago

I'm free now to hop into Discord and debug if that is easier 😄

nzlosh commented 1 year ago

ValueError: Failed to get the user 107624977066381312 ... that looks like it might be related to privileged intents not being enabled https://err-backend-discord.readthedocs.io/en/master/user_guide.html#failed-to-lookup-user. There are two parts, enabling them, one on the discord side and the other in errbot's configuration. https://err-backend-discord.readthedocs.io/en/master/configuration.html#errbot

GrantBirki commented 1 year ago

Ah ha getting closer, thank you! Looks like I need to enable this somehow:

2022-11-17 22:06:17,580 errbot INFO     errbot-backend-discord    Disabled intents - dm_messages, dm_typing
GrantBirki commented 1 year ago

Then my bot should be able to DM me when it starts

GrantBirki commented 1 year ago

Command execution is now working as well. Just need to sort out the DM part. Here is my config:

BOT_IDENTITY = {
    "token": os.environ.get("CHAT_SERVICE_TOKEN", None),
    "initial_intents": "all", # use all intents
    "intents": -20480, # use all intents
}

Trying to just give it all permissions possible to at least work then scope it down

GrantBirki commented 1 year ago

I added the following intents which resolved the DM intents being missing:

BOT_IDENTITY = {
    "token": os.environ.get("CHAT_SERVICE_TOKEN", None),
    "initial_intents": "all", # use all intents
    "intents": [1, 2, 8, 128, 256, 512, 4096, 16384, 32768]
}

but still hit the following error:

2022-11-17 22:10:11,881 errbot ERROR    errbot.plugin_manager     Error loading Boot.

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 557, in activate_plugin

    self._activate_plugin(plugin, plugin_info)

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 510, in _activate_plugin

    plugin.activate()

  File "/app/plugins/boot/boot.py", line 41, in activate

    self.warn_admins(INSTALL_MESSAGE_TEXT)

  File "/usr/local/lib/python3.9/site-packages/errbot/botplugin.py", line 596, in warn_admins

    self._bot.warn_admins(warning)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 417, in build_identifier

    return DiscordPerson(username=user, discriminator=tag)

  File "/app/backend/err-backend-discord/discordlib/person.py", line 67, in __init__

    self._user_id = member.id

AttributeError: 'NoneType' object has no attribute 'id'

2022-11-17 22:10:11,892 errbot ERROR    errbot.plugin_manager     Error loading Boot.

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 557, in activate_plugin

    self._activate_plugin(plugin, plugin_info)

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 510, in _activate_plugin

    plugin.activate()

  File "/app/plugins/boot/boot.py", line 41, in activate

    self.warn_admins(INSTALL_MESSAGE_TEXT)

  File "/usr/local/lib/python3.9/site-packages/errbot/botplugin.py", line 596, in warn_admins

    self._bot.warn_admins(warning)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 417, in build_identifier

    return DiscordPerson(username=user, discriminator=tag)

  File "/app/backend/err-backend-discord/discordlib/person.py", line 67, in __init__

    self._user_id = member.id

AttributeError: 'NoneType' object has no attribute 'id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 446, in activate_non_started_plugins

    self.activate_plugin(name)

  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_manager.py", line 563, in activate_plugin

    raise PluginActivationException(f"{name} failed to start : {e}.")

errbot.plugin_manager.PluginActivationException: Boot failed to start : 'NoneType' object has no attribute 'id'.

2022-11-17 22:10:11,902 errbot INFO     errbot.plugin_manager     Activate plugin: Ip.

2022-11-17 22:10:11,902 errbot WARNING  errbot.plugins.Ip         GEOLOCATION_KEY not found in environment variables. Disabling the ip plugin.

2022-11-17 22:10:11,903 errbot INFO     errbot.core_plugins.wsview Checking Ip for webhooks

2022-11-17 22:10:11,903 errbot INFO     errbot.plugin_manager     Activate plugin: Play.

2022-11-17 22:10:11,905 errbot INFO     errbot.core_plugins.wsview Checking Play for webhooks

2022-11-17 22:10:11,905 errbot INFO     errbot.plugin_manager     Activate plugin: Covid.

2022-11-17 22:10:11,907 errbot INFO     errbot.core_plugins.wsview Checking Covid for webhooks

2022-11-17 22:10:11,908 errbot INFO     errbot.plugin_manager     Activate flow: PlayFlow

2022-11-17 22:10:11,908 errbot ERROR    discord.client            Ignoring exception in on_ready

Traceback (most recent call last):

  File "/home/errbot/.local/lib/python3.9/site-packages/discord/client.py", line 409, in _run_event

    await coro(*args, **kwargs)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 69, in on_ready

    self.connect_callback()

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 882, in connect_callback

    self.warn_admins(errors)

  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 790, in warn_admins

    self.send(self.build_identifier(admin), warning)

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 417, in build_identifier

    return DiscordPerson(username=user, discriminator=tag)

  File "/app/backend/err-backend-discord/discordlib/person.py", line 67, in __init__

    self._user_id = member.id

AttributeError: 'NoneType' object has no attribute 'id'
nzlosh commented 1 year ago

Good to hear. It looks like you've copied and pasted the examples from the documentation. They are just arbitrary example which may or may not work. These are settings I use on my setup and things work correctly:

    "initial_intents": "default",
    "intents": ["members", "-presences", "message_content"]
GrantBirki commented 1 year ago

Here is the commit I pushed to try and fix it but still no luck:

https://github.com/GrantBirki/errbot/pull/152/commits/7ca184600b641672968d06e3d877908a4b3631ea

GrantBirki commented 1 year ago

Everything seems to work but the startup DM to admins (me)

GrantBirki commented 1 year ago

Ah shoot my favorite command fails as well!

I have a command called .play which joins a voice channel and plays a song

It gets the following error:

2022-11-17 22:19:20,904 errbot ERROR    errbot.plugins.Play       The play_cron() failed! - Error: Can't send a message on a non-existent channel

Traceback (most recent call last):

  File "/app/plugins/play/play.py", line 111, in play_cron

    chatutils.send_card_helper(

  File "/app/plugins/lib/chat/chatutils.py", line 215, in send_card_helper

    bot_self.send_card(

  File "/usr/local/lib/python3.9/site-packages/errbot/botplugin.py", line 656, in send_card

    self._bot.send_card(

  File "/app/backend/err-backend-discord/err-backend-discord.py", line 225, in send_card

    asyncio.run_coroutine_threadsafe(

  File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 446, in result

    return self.__get_result()

  File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result

    raise self._exception

  File "/app/backend/err-backend-discord/discordlib/room.py", line 230, in send

    raise RuntimeError("Can't send a message on a non-existent channel")

RuntimeError: Can't send a message on a non-existent channel

2022-11-17 22:19:23,083 errbot ERROR    lib.common.errhelper      Can't send a message on a non-existent channel
nzlosh commented 1 year ago

Can you use the same configuration settings as I posted earlier and try run the !whoami command and show what you get?

This what I get:

| key      | value
| -------- | --------
| person   | nzlosh#0xxx
| nick     | nzlosh
| fullname | nzlosh#0xxx
| client   | <discord.client.Client object at 0x7efc302c3430>
| email    | Unavailable

- string representation is 'nzlosh#0xxx'
- class is 'DiscordPerson'
nzlosh commented 1 year ago

By the way, if you want to discuss things via chat, I'm on the errbot gitter channel. https://gitter.im/errbotio/errbot

GrantBirki commented 1 year ago

@nzlosh The following commit fixed my first issue where the bot could not DM me on startup!

https://github.com/GrantBirki/errbot/pull/152/commits/6a1421c70531696e26067221a4c7ad06cc0ac2f5

I needed to add some code to remove the @ as that was making it fail. You may want to consider adding this if it is a bug or not

GrantBirki commented 1 year ago

Also, in my testing I found something else and fixed it with this kinda gross commit.. https://github.com/GrantBirki/errbot/pull/152/commits/bbfad237d4b0e6c226ecf3594bdfb35376ede416

We are comparing a type of String to an Int. So it will never find a "match" and think that the channel does not exist if we try and send an "out of band" Card to a Discord channel

GrantBirki commented 1 year ago

For anyone else doing rather custom stuff with errbot and the Discord backend, the following three PRs resolved 99% of my issues:

GrantBirki commented 1 year ago

One more PR to fix ACLs issues with the new @ prefix for Bot admins

https://github.com/GrantBirki/errbot/pull/158

fernand0 commented 1 year ago

Well, after my intents activation it seemed to be working, but that was not the case. With @GrantBirki version (downloaded from his repo and copied the relevant directory to my backends dir) it seems to be fine now.