lloesche / valheim-server-docker

Valheim dedicated gameserver with automatic update, World backup, BepInEx and ValheimPlus mod support
https://hub.docker.com/r/lloesche/valheim-server
Apache License 2.0
1.95k stars 275 forks source link

Player spawn Discord notification doesn't work #696

Open NorskNoobing opened 4 months ago

NorskNoobing commented 4 months ago

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"; }'
lucasgmarques commented 1 month ago

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"; }'
NorskNoobing commented 1 month ago

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: image

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"; }'

image

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?