This tutorial aims to give you knowledge about how to use a webhook to log important events from your server right into a discord channel.
Creating a Webhook
Create a channel.
Go to: Edit channel -> Integrations ->view webhooks -> New webhook
Copy the webhook URL.
I'll call mine Spicy.
Using the Webhook
Now we'll create a small server-side function that'll help us use the webhook.
Notes:
Replace <webhook URL> with the webhook URL that you just copied
Replace <serverLogo URL> with the desired server logo picture URL.
Now here's a small example of how to use it:
// Triggers once player joins the server...
// Simple log when player joins server
mp.events.add('playerJoin', (player) => {
mp.discord.sendMessage(`Player Joined`, player.name, [], mp.discord.colors.GREY);
});
// Another one with fields included
mp.events.add('playerJoin', (player) => {
let fields = [{
name: `Player's IP`,
value: player.ip,
inline: false
}]
mp.discord.sendMessage(`Player joined the server [${mp.players.toArray().length}/${mp.config.maxplayers}]`, player.name, fields, mp.discord.colors.GREEN);
});
Enjoy spamming discord....
Regards, Keptin