Skip to content

Commit c3b31cb

Browse files
Update discordServerInfo.ser
1 parent dd0068c commit c3b31cb

1 file changed

Lines changed: 23 additions & 27 deletions

File tree

Example Scripts/discordServerInfo.ser

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,35 @@
33
# this is the webhook URL, please set one here in order for this script to work
44
$url = ""
55

6-
func SetDiscordMessage
7-
# get player amount
8-
$text = "There are {AmountOf @all} players on the server"
6+
func *GetDiscordMessage
7+
# variables using 'ephm' are ephemeral and will be deleted after the function ends
8+
ephm $title = "{ServerInfo name} status"
9+
ephm $content = "There are {AmountOf @all} players on the server:{Show @all name "<br> -" true}"
910

10-
# list each player
11-
over @all with @plr
12-
# <br> creates a new line
13-
$text = JoinText $text "<br>- {@plr -> name}"
14-
end
15-
16-
*embed = DiscordEmbed "📡 {ServerInfo name} status 📡" $text
17-
*msg = DiscordMessage _ "{ServerInfo name} status" _ *embed
18-
19-
# remove unneeded variables
20-
delete $text
21-
delete *embed
11+
return DiscordMessage _ $title _ {DiscordEmbed $title $content}
2212
end
2313

2414
if {$url -> length} is 0
2515
Error "Script '{This name}' cannot run, because the webhook URL was not set!"
2616
stop
2717
end
2818

29-
# create a message to later edit
30-
# IMPORTANT! this will create message every round
31-
# if you wish to not, just hardcode the message id
32-
run SetDiscordMessage
33-
$messageId = SendDiscordMessageAndWait $url *msg
34-
35-
# update the message every 2 seconds
36-
forever
37-
wait 2s
38-
39-
run SetDiscordMessage
40-
EditDiscordMessage $url $messageId *msg
19+
# use an attempt statement in case something goes wrong
20+
# like an invalid URL error
21+
attempt
22+
# create a message to later edit
23+
# IMPORTANT! this will create message every round
24+
# if you wish to not, just hardcode the message id
25+
*msg = run *GetDiscordMessage
26+
$messageId = SendDiscordMessageAndWait $url *msg
27+
28+
# update the message every 2 seconds
29+
forever
30+
wait 2s
31+
32+
*msg = run *GetDiscordMessage
33+
EditDiscordMessage $url $messageId *msg
34+
end
35+
on_error with $err
36+
Error ($err + " Make sure that the webhook URL is correct!")
4137
end

0 commit comments

Comments
 (0)