1+ using JetBrains . Annotations ;
2+
3+ namespace SER . Code . Examples ;
4+
5+ [ UsedImplicitly ]
6+ public class DiscordServerInfoScript : Example
7+ {
8+ public override string Name => "discordServerInfo" ;
9+
10+ public override string Content =>
11+ """
12+ !-- OnEvent WaitingForPlayers
13+
14+ # this is the webhook URL, please set one here in order for this script to work
15+ $url = "https://discord.com/api/webhooks/1464230955945431217/jzQw9SZCFc3yhLf22yzsgiktbQk0Ra4J-_kuVqADOgNNKERSTw9qlHmVjRJz3DKj7vVi"
16+
17+ func SetDiscordMessage
18+ # get player amount
19+ $text = "There are {AmountOf @all} players on the server"
20+
21+ # list each player
22+ foreach @all
23+ with @plr
24+
25+ # <br> creates a new line
26+ $text = JoinText $text "<br>- {@plr name}"
27+ end
28+
29+ *embed = DiscordEmbed "📡 {ServerInfo name} status 📡" $text
30+ *msg = DiscordMessage _ "{ServerInfo name} status" _ *embed
31+
32+ # remove unneeded variables
33+ PopVariable local $text
34+ PopVariable local *embed
35+ end
36+
37+ if {TextLength $url} is 0
38+ Error "Script '{This name}' cannot run, because the webhook URL was not set!"
39+ stop
40+ end
41+
42+ # create a message to later edit
43+ # IMPORTANT! this will create message every round
44+ # if you wish to not, just hardcode the message id
45+ run SetDiscordMessage
46+ $messageId = SendDiscordMessageAndWait $url *msg
47+
48+ # update the message every 2 seconds
49+ forever
50+ Wait 2s
51+
52+ run SetDiscordMessage
53+ EditDiscordMessage $url $messageId *msg
54+ end
55+ """ ;
56+ }
0 commit comments