Hello, Minecraft community! I present to your attention a script written in Skript for sending messages to Discord via a webhook URL.
You can generate messages in JSON format and send them to the webhook of the URL Discord channel.
The script has two main functions. The first one generates a message in JSON format, and the second one sends this message to the Discord channel.
1.
Function prepareDiscordMessage Function to format message in JSON format.
Parameters: ● avatarUrl: Avatar for Discord bot ● botUsername: Username for Discord bot ● embedTitle: Embed title ● embedDescription: Embed description ● embedFooter: Footer text ● embedColor: Embed color
Usage example: An example of the result of formatting a message for further sending as a message to the Discord channel.
Code (Text):
set {_discordMessage} to prepareDiscordMessage(BotAvatar(), BotUsername(), "%event-player% has joined the server", "The player **%event-player%** has joined the server.", FooterText(), GreenColor())
Result:
Code (Text):
'{ ""embeds"": [{ ""title"": ""CHYZHOV has joined the server"", ""description"": ""The player **CHYZHOV** has joined the server."", ""color"": 3066993, ""footer"": { ""text"": ""Date of action execution: 02.11.2024, 02:49"" } }], ""username"": ""System alert"", ""avatar_url"": ""https://cdn.discordapp.com/attachments/1014147200701435965/1294052865836318791/star-fall-svgrepo-com.png?ex=6714d0e5&is=67137f65&hm=aecc0259e4c8eda035b42ac9b414ea87c6d1d7e82a23fa21a3519273ef64ded3&"" }'
2.
Function sendDiscordMessage Function for sending messages to the Discord channel.
Parameters: ● message: Message in JSON format
● channel: Channel webhook URL
Usage example: When a player joins a server, a message will be sent to the Discord channel about it.
Code (Text):
on join:
set {_discordMessage} to prepareDiscordMessage(BotAvatar(), BotUsername(), "%event-player% has joined the server", "The player **%event-player%** has joined the server.", FooterText(), GreenColor())
sendDiscordMessage({_discordMessage}, Channel())
Result: The message was sent to the Discord channel.
For more convenient use of the script, you can use such functions as those listed below. Override the values in the functions below.
1.
Bot avatar Specify a link to the bot's avatar, which will be displayed in the discord message.
Code (Text):
function BotAvatar() :: string:
return "https://cdn.discordapp.com/attachments/1014147200701435965/1294052865836318791/star-fall-svgrepo-com.png?ex=6714d0e5&is=67137f65&hm=aecc0259e4c8eda035b42ac9b414ea87c6d1d7e82a23fa21a3519273ef64ded3&"
2.
Bot username The name of the bot will be displayed in the discord message.
Code (Text):
function BotUsername() :: string:
return "System alert"
3.
Footer text The text will be displayed in the footer of the Discord message.
Code (Text):
function FooterText() :: string:
return "Date of action execution: %now%"
4.
Red color The color code variant for the embed in the Discord message.
Code (Text):
function RedColor() :: integer:
return 13458524
5.
Yellow color The color code variant for the embed in the Discord message.
Code (Text):
function YellowColor() :: integer:
return 15844367
6.
Green color The color code variant for the embed in the Discord message.
Code (Text):
function GreenColor() :: integer:
return 3066993
7.
Channel Link to the webhook of the URL channel to which the message will be sent.
Code (Text):
function Channel() :: string:
return "https://discord.com/api/webhooks/your_webhook"
Please pay attention to this information! For the script to work, you need to install some plugins.