Automatic death command is not working

Asked Oct 10, 2025·3 replies·Last activity 10 months ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

I'm trying to create an auto death counter command but it's not working. I used an AI to generate it, and I've come to the conclusion that Nightbot can't execute the command because it's too complex. Is this true, or is it more likely that the code is just wrong?

Command to DISPLAY:

!addcom !deaths The streamer has died 0 times.

Command to ADD:

!addcom !adddeath -ul=moderator -a=$(eval const text = \$(urlfetch json https://nightbot.tv/1/commands/lookup?q=!deaths )\.trim(); const match = text.match(/\\d+/); const current = match ? parseInt(match\[0\]) : 0; const add = parseInt('$(query)') || 1; const total = current + add; \!editcom !deaths The streamer has died ${total} times.\)

Command to RESET:

!addcom !resetdeaths -ul=moderator -a=!editcom !deaths The streamer has died 0 times.

The AI says the error is as follows:

To understand why, we have to look at the "chain of execution"—the sequence of steps Nightbot must take to run the command:

1. A user runs !adddeath, which triggers the alias (-a=) function.

2. The alias needs to execute the result of the $(eval) script.

3. To get that result, the $(eval) script must first use the $(urlfetch) variable to read the !deaths command from Nightbot's server.

4. The $(eval) script then calculates the new total and generates a complete, new command as a line of text (e.g., !editcom !deaths The streamer has died 5 times.).

5. Finally, the alias (-a=) from Step 1 is supposed to take this text and execute it as a command.

Our tests proved that this chain breaks at the final step. The alias (-a=) function appears to be unable to execute a command that was generated by a script that is as complex as this one (containing both eval and urlfetch).

3 replies

I don’t know how automatic you mean, I’ll give you my point of view to see if I understood what you wanted to achieve

[u]First command:[/u]

!addcom !deaths The streamer has died 0 times.

→ This command could be used by any user [u]without editing[/u] the counter

[u]Second command:[/u]

!addcom !adddeath !editcom !deaths -ul=moderator The streamer has died $(count) times.

→ This command is so that a moderator can add to the counter.

[u]Third command:[/u]

!addcom !resetdeaths !editcom !deaths -ul=moderator The streamer has died 0 times.

→ This command is so that a moderator can reset the counter to 0.

This is almost good, however the reset commands should not edit !deaths. !resetdeaths should reset the $(count) of !adddeath. Otherwise the count will keep adding up.

So more like:
\!addcom !resetdeaths -ul=moderator -a=!editcom !adddeath -c=-1\

For resetting, you use !resetdeaths first, then !adddeath once.
!resetdeaths to reset the counter (we use -1 so after !adddeath it will be 0)
!adddeath to rest the actual !deaths command.

Gerhard said:
d

Ok, I understand, thanks for the answers. Could you tell me if the main !adddeath command works? It's just that when I use it, it doesn't work; it doesn't add the deaths to the counter as it should, it stays at 0.