DevTeVe
(DevTek Ve)
Dezembro 3, 2025, 4:05pm
243
Encontrei um bug (e criei um PR para corrigi-lo) ao tentar usar o Discord Persona Bot
Job exception: context must be an instance of BotContext
/var/www/discourse/plugins/discourse-ai/lib/personas/bot.rb:55:in `reply'
/var/www/discourse/plugins/discourse-ai/lib/discord/bot/persona_replier.rb:25:in `handle_interaction!'
/var/www/discourse/plugins/discourse-ai/app/jobs/regular/stream_discord_reply.rb:13:in `execute'
main ← sunnypilot:fix-discord-persona
opened 04:03PM - 03 Dec 25 UTC
**What is the problem?**
When using the Discord integration in `persona` mode (… `SiteSetting.ai_discord_search_mode == "persona"`), triggering a slash command causes the background job to fail.
The `DiscourseAi::Discord::Bot::PersonaReplier` was passing a raw `Hash` to the `DiscourseAi::Personas::Bot#reply` method. However, `Bot#reply` enforces that the input must be an instance of `DiscourseAi::Personas::BotContext`.
**What is the fix?**
I updated `handle_interaction!` in `lib/discord/bot/persona_replier.rb` to correctly initialize a `BotContext` object with the user query and options before passing it to the bot.
I've learned this by seeing it on https://github.com/discourse/discourse/blob/main/plugins/discourse-ai/app/jobs/regular/stream_discover_reply.rb#L36-L41
**Stack Trace / Error Logs**
```text
Job exception: context must be an instance of BotContext
/var/www/discourse/plugins/discourse-ai/lib/personas/bot.rb:55:in `reply'
/var/www/discourse/plugins/discourse-ai/lib/discord/bot/persona_replier.rb:25:in `handle_interaction!'
/var/www/discourse/plugins/discourse-ai/app/jobs/regular/stream_discord_reply.rb:13:in `execute'
```
Here's a little proof of it working on my Discord test server
<img width="886" height="165" alt="image" src="https://github.com/user-attachments/assets/c11f93c6-e719-4876-b4c2-c238527f9153" />
2 curtidas