Player spawn Discord notification doesn't work
I set up the Discord player spawn notification from the log filter using the steps in the readme. I translated it into my composefile, but it doesn't seem to work. No error is logged in the container logs, and I don't get any messages on Discord. I tested the server start notification via Discord, and it worked properly.
Are there any syntax issues? How could I troubleshoot this? Is there another logfile for these types of logs?
Here's how the relevant env-vars look:
environment:
- DISCORD_WEBHOOK=REDACTED
- VALHEIM_LOG_FILTER_CONTAINS_Spawned="Got character ZDOID from"
- 'ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ read l; l=$${l//*ZDOID from /}; l=$${l// :*/}; msg="Player $$l spawned into the world"; curl -sfSL -X POST -H "Content-Type: application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$msg\"}" "$$DISCORD_WEBHOOK"; }'
I setup an env file for my server and and the notification works properly.
Try this:
environment:
- DISCORD_WEBHOOK=REDACTED
- VALHEIM_LOG_FILTER_CONTAINS_Spawned="Got character ZDOID from"
- ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned='{ read l; l=$${l//*ZDOID from /}; l=$${l// :*/}; msg="Player $$l spawned into the world"; curl -sfSL -X POST -H "Content-Type: application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$msg\"}" "$$DISCORD_WEBHOOK"; }'
I copied your exact settings, but when I ran docker compose up -d I got the following error:
> docker compose up -d valheim-server
services.valheim-server.environment.[14]: unexpected type map[string]interface {}
This seems to be because the composefile doesn't interpret the whole thing as a string, which is weird because it doesn't have any single quotes ' inside the string. Only the purple part is interpreted as a string:
Therefore I tried putting the whole env-var inside of single quotes, instead of just the value, and that doesn't throw any error. However I still don't get any message when I join the server.
environment:
- DISCORD_WEBHOOK=REDACTED
- VALHEIM_LOG_FILTER_CONTAINS_Spawned="Got character ZDOID from"
- 'ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ read l; l=$${l//*ZDOID from /}; l=$${l// :*/}; msg="Player $$l spawned into the world"; curl -sfSL -X POST -H "Content-Type: application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$msg\"}" "$$DISCORD_WEBHOOK"; }'
I also looked into the container logs, just to make sure that the log event actually happens when I join, and it seems to be fine:
2024-10-10T10:07:36.466498350Z Oct 10 12:07:36 supervisord: valheim-server 10/10/2024 12:07:36: Got character ZDOID from ${CHARACTER_NAME} : ${SOME_PLAYER_ID_?}
Is there any logs for the discord message/log filter triggers that I can look into for troubleshooting? Does it work for you when using the exact same env-vars that I used in the example above?
I copied your exact settings, but when I ran
docker compose up -dI got the following error:docker compose up -d valheim-server services.valheim-server.environment.[14]: unexpected type map[string]interface {}
This seems to be because the composefile doesn't interpret the whole thing as a string, which is weird because it doesn't have any single quotes
'inside the string. Only the purple part is interpreted as a string:Therefore I tried putting the whole env-var inside of single quotes, instead of just the value, and that doesn't throw any error. However I still don't get any message when I join the server.
environment:
- DISCORD_WEBHOOK=REDACTED
- VALHEIM_LOG_FILTER_CONTAINS_Spawned="Got character ZDOID from"
- 'ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ read l; l=$${l//ZDOID from /}; l=$${l// :/}; msg="Player $$l spawned into the world"; curl -sfSL -X POST -H "Content-Type: application/json" -d "{"username":"Valheim","content":"$$msg"}" "$$DISCORD_WEBHOOK"; }'
I also looked into the container logs, just to make sure that the log event actually happens when I join, and it seems to be fine:
2024-10-10T10:07:36.466498350Z Oct 10 12:07:36 supervisord: valheim-server 10/10/2024 12:07:36: Got character ZDOID from ${CHARACTER_NAME} : ${SOME_PLAYER_ID_?}Is there any logs for the discord message/log filter triggers that I can look into for troubleshooting? Does it work for you when using the exact same env-vars that I used in the example above?
Did you ever get anywhere with this? I'm running into the same error.
Did you ever get anywhere with this? I'm running into the same error.
I tested out different approaches by following documentation, thinking of different scenarios it could work in, and tried asking ChatGPT for solutions, but I never got anywhere. I haven't gotten an answer to the following question either:
Is there any logs for the discord message/log filter triggers that I can look into for troubleshooting?
So, I haven't found a solution yet. If you're able to find one, I'd be grateful if you could share it here. :)
Did you ever get anywhere with this? I'm running into the same error.
I tested out different approaches by following documentation, thinking of different scenarios it could work in, and tried asking ChatGPT for solutions, but I never got anywhere. I haven't gotten an answer to the following question either:
Is there any logs for the discord message/log filter triggers that I can look into for troubleshooting?
So, I haven't found a solution yet. If you're able to find one, I'd be grateful if you could share it here. :)
Ok, I came back to this after messing with it for a couple hours yesterday and fixed it in 10 minutes.
The fix was removing the damn space after the : in Content-Type: application/json so it looked like:
- ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ read l; l=$${l//*ZDOID from /}; l=$${l// :*/}; msg="Player $$l spawned into the world"; curl -sfSL -X POST -H "Content-Type:application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$msg\"}" "$$DISCORD_WEBHOOK"; }
This worked for me.
- ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ read l; l=$${l//*ZDOID from /}; l=$${l// :*/}; msg="Player $$l spawned into the world"; curl -sfSL -X POST -H "Content-Type:application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$msg\"}" "$$DISCORD_WEBHOOK"; }
And you confirmed that you got the message in Discord? I copied your config, and still got the same problem. Are you able to share your complete config, with redactions of course?
- ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ read l; l=$${l//*ZDOID from /}; l=$${l// :*/}; msg="Player $$l spawned into the world"; curl -sfSL -X POST -H "Content-Type:application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$msg\"}" "$$DISCORD_WEBHOOK"; }And you confirmed that you got the message in Discord? I copied your config, and still got the same problem. Are you able to share your complete config, with redactions of course?
Yes, I confirmed it worked. Here is my whole config:
services:
valheim:
image: ghcr.io/lloesche/valheim-server
cap_add:
- sys_nice
volumes:
- /mnt/TruPool/gameservers/valheim/config:/config
- /mnt/TruPool/gameservers/valheim/data:/opt/valheim
ports:
- "2456-2458:2456-2458/udp"
- "9011:9001/tcp"
environment:
- SERVER_NAME="<redacted>"
- SERVER_PORT=2456
- WORLD_NAME=<redacted>
- SERVER_PASS=<redacted>
- SERVER_PUBLIC=false
- SUPERVISOR_HTTP=true
- SUPERVISOR_HTTP_PASS=<redacted>
- TZ=America/Phoenix
#RESTART / BACKUPS
- RESTART_CRON='0 24 * * *'
- BACKUPS_MAX_AGE=10
#DISCORD
- DISCORD_WEBHOOK=<redacted>
- VALHEIM_LOG_FILTER_CONTAINS_Spawned=Got character ZDOID from
- ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ read l; l=$${l//*ZDOID from /}; l=$${l// :*/}; msg="Player $$l spawned into the world"; curl -sfSL -X POST -H "Content-Type:application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$msg\"}" "$$DISCORD_WEBHOOK"; }
restart: always
stop_grace_period: 2m
I use Portainer to manage my dockers on TrueNas.
Yes, I confirmed it worked. Here is my whole config:
Thanks, I had quotes surrounding the value of log filter contains, so it looked like VALHEIM_LOG_FILTER_CONTAINS_Spawned="Got character ZDOID from". After changing it to the value above, it worked! Thanks for helping out :)
I have a little more of an extensive discord notification config, so for future reference, this is all the discord-relevant config (incl. auto-update), that's currently working in my docker-compose.yml:
environment:
- DISCORD_WEBHOOK=$VALHEIM_DISCORD_WEBHOOK
# Discord start message
- DISCORD_START_MESSAGE=Starting Valheim server $$SERVER_NAME
- PRE_BOOTSTRAP_HOOK=curl -sfSL -X POST -H "Content-Type:application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$(eval echo $$DISCORD_START_MESSAGE)\"}" "$$DISCORD_WEBHOOK"
# Discord player spawn message
- VALHEIM_LOG_FILTER_CONTAINS_Spawned=Got character ZDOID from
- ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ read l; l=$${l//*ZDOID from /}; l=$${l// :*/}; msg="Player $$l spawned into the world"; curl -sfSL -X POST -H "Content-Type:application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$msg\"}" "$$DISCORD_WEBHOOK"; }
# Discord Valheim auto-update message
- DISCORD_RESTART_MESSAGE=Restarting Valheim server in one minute!
- PRE_RESTART_HOOK=curl -sfSL -X POST -H "Content-Type:application/json" -d "{\"username\":\"Valheim\",\"content\":\"$$DISCORD_RESTART_MESSAGE\"}" "$$DISCORD_WEBHOOK" && sleep 60
# Auto-update settings
- UPDATE_IF_IDLE=true
- RESTART_CRON=0 5 * * *
- RESTART_IF_IDLE=true