#Agent cant create discord thread from cronjob

1 messages · Page 1 of 1 (latest)

cobalt jasper
#

Im invoking an agent using openclaw agent command and in the agents.md i have defined that the agent should create a new thread in discord with the findings of his task. Unfortunately this doesnt work and i was wondering why? When i ask the agents bot in discord directly to create a thread it works.

manic kindleBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> âś… Mark Solution

copper owlBOT
# cobalt jasper Im invoking an agent using openclaw agent command and in the agents.md i have de...

When you run an agent from Discord, the run is bound to that Discord event (it knows the channelId and the triggering messageId). So “create a thread” can be done as start thread from this message, which Discord allows in many setups.

When you run the same agent via openclaw agent (often from cron/CLI), there is no Discord inbound message context. That usually breaks in one (or both) of these ways:

  1. No thread anchor (messageId)
    The agent ends up trying to create a thread without a parent message (Discord API: start thread without message), which may fail depending on channel type + permissions.

  2. Cross-context guard (CLI/cron → Discord)
    Tool calls that try to post to Discord can be blocked unless cross-context messaging is allowed (similar to the FAQ’s “Cross-context messaging denied” section). From the agent’s POV, a CLI/cron run is not “in Discord”, so proactive Discord actions may be denied.

Fix options

Option A (most reliable): have the agent create its own anchor message, then thread off it
In your AGENTS.md instructions, force this sequence:

  1. message.send to the target Discord channel (“Starting report…”)
  2. take the returned messageId
  3. message.thread-create with that messageId
#
  1. post findings in the thread

(Without step 1, you’re relying on “thread without message”, which often fails.)

Option B: allow cross-context messaging for that agent
Config (from the FAQ section) under the agent (or defaults):

{
  agents: {
    defaults: {
      tools: {
        message: {
          crossContext: {
            allowAcrossProviders: true,
          },
#

Quick debug question

What does it fail with? If you paste:

  • openclaw --version
  • the relevant error line from openclaw logs --follow while the agent runs

…I can tell you immediately whether it’s the missing messageId path vs cross-context denied.

cobalt jasper
#

ok, this is working now, i added a default bot token in the config and provided the agent with detailed infos about the guild and the channel. one more problem now: i want to mention another bot in this thread (in a forum btw), and the text itself (@bot-i-want-to-mention) is in the body of the thread, but the bot isnt mentioned. how can i fix this?

copper owlBOT
# cobalt jasper ok, this is working now, i added a default bot token in the config and provided ...

In Discord, @bot-name in a message is just plain text unless it’s the real mention token. When you “mention” from the Discord UI, it actually inserts something like:

<@BOT_USER_ID>

So to make your agent mention/ping another bot, have it output the ID form, e.g.:

Hey @umbral holly can you take a look at this thread?

How to get the bot’s ID / mention token:

  • Enable Developer Mode (Discord → User Settings → Advanced), then right-click the bot → Copy User ID
  • Or in Discord chat, type \@BotName (backslash before the @) and Discord will show the raw <@...> form you can copy.
#

Forum/thread gotcha (since you mentioned a forum): OpenClaw auto-derives the thread title from the first non-empty line when it creates a forum post, so keep the first line a normal title, and put the <@...> mention on the next line.

cobalt jasper
#

when i use openclaw message thread create i get error: missing access. how can i execute this command so that my bot is creating the thread?

copper owlBOT
# cobalt jasper when i use openclaw message thread create i get error: missing access. how can i...

Discord’s Missing Access (error code 50001) basically means the bot token you’re using cannot “see” that channel (not in the guild, wrong token/account, or the channel is private / denied via overrides). It’s not an OpenClaw/CLI-only thing — it’s the Discord API refusing the bot.

Things to check / fix:

  1. Make sure the CLI is using the same bot token that’s actually in your server
  • If you have multiple Discord accounts configured, pass the right one: --account <id>
  • Quick sanity check: run
    openclaw message channel info --channel discord --target channel:<PARENT_CHANNEL_ID> --verbose
    
    If that returns Missing Access too, the bot simply can’t access that channel.
  1. Verify the permissions in the parent channel you’re targeting
    In the channel’s permissions (or category overrides), the bot role needs at least:
  • View Channel
  • Send Messages (in forum channels this shows as “Create Posts”)
#

For threads in normal text channels, also ensure:

  • Create Public Threads (and Send Messages in Threads for replying inside them)
  1. Make sure you’re targeting the right ID
  • openclaw message thread create wants --target = the parent channel id (the text channel / forum channel), not an existing thread id.

Practical tip (forums): if your target is a forum channel, you often don’t need thread create at all — send will auto-create a forum post/thread:

openclaw message send --channel discord \
  --target channel:<FORUM_CHANNEL_ID> \
  --message "Title line\n\nBody text..."

Docs: https://docs.openclaw.ai/cli/message (see “Threads” + “send” behavior)

If you paste the exact command you ran (and whether --target is a forum channel id or a text channel id), I can tell you which permission/ID is the mismatch.

cobalt jasper
#

how can i execute this command as the bot? right now im in the shell on the machine where the gateway runs and try to execute these commands

copper owlBOT
# cobalt jasper how can i execute this command as the bot? right now im in the shell on the mach...

You are executing it “as the bot” already.

openclaw message … talks to Discord via the Bot API, and the only identity it can use is whatever bot token OpenClaw resolves from your config/env. There is no “run as my Discord user” mode (and you wouldn’t want that; userbots are against Discord ToS).

So if you see Missing Access (50001), it’s not because you’re in the wrong shell — it means that bot token cannot access the target channel (not in the guild, no View Channel, private channel/category denies, wrong bot account, wrong channel id, etc.).

1) First confirm your CLI and the Gateway are using the same config/profile

Run on the gateway host:

openclaw gateway status

Check Config (cli) vs Config (service). If they differ, your CLI is reading a different OPENCLAW_CONFIG_PATH / --profile than the service.

(FAQ says this is the common cause; fix is openclaw gateway install --force from the profile you want the service to use.)

#

2) Confirm which bot token/account the CLI is using

  • Default token sources:
    • config: channels.discord.token (default account)
    • env fallback (default account only): DISCORD_BOT_TOKEN
    • multi-account: channels.discord.accounts.<accountId>.token + run CLI with --account <accountId>

If you configured multiple Discord accounts, try explicitly:

openclaw message thread create --channel discord --account <accountId> \
  --target channel:<parentChannelId> --thread-name "test" --message "hi" --verbose

3) Fix “Missing Access” in Discord (permissions/visibility)

In the parent channel you’re targeting (or its category overrides), ensure the bot has:

  • View Channel
  • Send Messages (in forums this is Create Posts)
#

And if you’re creating threads from a normal text channel:

  • Create Public Threads (and usually Send Messages in Threads)

Forum tip

If your “channel” is a forum, you often don’t need thread create at all — just:

openclaw message send --channel discord --target channel:<forumChannelId> \
  --message "Title line\n\nBody text…"

OpenClaw will auto-create the forum post/thread.

If you paste the exact command you ran + whether the target is a forum channel or a normal text channel, I can tell you which permission is missing / whether the ID is the wrong one.

cobalt jasper
#

when i use the approach you described earlier, so that i create the thread from the cronjob with the bot account, which returns a message id, can i pass this message id to the agent so that it can send a message to this thread in the forum?

copper owlBOT
# cobalt jasper when i use the approach you described earlier, so that i create the thread from ...

Yes — but you’ll want to pass the thread’s channel id (threadId), not the starter message id (messageId).

In Discord, a “thread” (including a Forum post) is its own channel. To post into it, the agent needs that channel/thread id and then it can do something like:

  • create the thread (forum post): message(action="thread-create", channelId=<FORUM_CHANNEL_ID>, threadName="…") → get back a threadId
  • write into it: message(action="thread-reply", threadId=<THREAD_ID>, message="…") (or sometimes send targeting the thread)

Two important gotchas:

  1. A cronjob can’t really “return a value” that OpenClaw automatically feeds into a later agent run. So if you’re thinking “cron creates thread → agent later posts into that thread”, there’s no built-in variable-passing pipeline.

  2. The simplest reliable pattern is: have the agent create the thread and immediately post the findings into it in the same run (so it already has the threadId from the create call).

If you tell me whether your “cron creates the thread” step is using thread-create (and what it prints/returns), I can tell you exactly which ID in that output is the one to pass along.

cobalt jasper
#

this is how it looks like in my regular cronjob.sh that i set up using the normal crontab on the gateway server:

MESSAGE=$(openclaw message thread create \
  --channel discord \
  --target channel:xxx \
  --thread-name "$ISSUE_SUMMARY" \
  --account dispatcher-bot \
  --json 2>/dev/null)

THREAD_ID=$(echo "$MESSAGE" | jq -r '".payload.thread.id"')

openclaw agent \
  --agent dispatcher \
  --message "Neue Issues zur Klassifikation:
$ISSUE_SUMMARY

Infos fĂĽr Discord Zugriff:
Guild Id: xxx
Channel Id: channel:xxx
Bot User Id fĂĽr mention (planner-bot): xxx

Die thread Id des erstellten Threads im Forum ist $THREAD_ID, schreibe deine Klassifikation darunter als Kommentar.

"

the agent then returns
Problem: Discord-Thread-Erstellung schlägt fehl mit Missing Access.

Der default Discord-Bot-Account hat keine Berechtigung, Threads im code-threads Forum zu erstellen. Bitte:

  1. Bot-Berechtigungen im Discord Server fĂĽr code-threads prĂĽfen
  2. Create Threads und Send Messages in Threads fĂĽr die Bot-Rolle aktivieren
  3. Bot explizit in die Channel-Whitelist aufnehmen

why is it trying to use the default discord bot?