The online racing simulator
Discord - How To
(2 posts, closed, started )
Discord - How To
Hello,

I've created a small tutorial, how to set-up your LFSLapper to communicate with your discordbot.
This tutorial will be extended with more code examples in the future.

You can PM me, if you have usefull code examples or more tips&tricks, i can add to this tutorial.
Asking for help with Discord will be ignored. Go To: https://www.lfs.net/forum/455-General-Support



#1. Create a DiscordBot @ https://discord.com/developers/applications
Here is an tutorial how to setup your bot properly
https://www.ionos.com/digitalguide/server/know-how/creating-discord-bot/

#2. Once you've added your bot to your discord server, we can now configure LFSLapper to communicate with your discordbot.

#3. Open myInc.LPR (bin\default\includes\myInc.lpr) and fill in the 3 parameters
#####DISCORD API#####
$DiscordToken = ""; # Token to connect LFSLapper with Discord , This is a token with alot of characters
Example: NTY5MjU1234567890NTMy.G12345.36as1234lT9PcdFBd-9niSnIOabcDEFGHJ
$DiscordChannelReceive = ""; # This can be blank or you can add up to 5 discordchannels ID's for receiving LFSLapper messages, seperated with a comma "," .
The Discordchannel ID's can be found when you rightclick on the channel and click on "Copy Channel ID".

$DiscordBotStatus = "Powered by LFSLapper!";

#4. Start LFSLapper
When LFSLapper is connected to your LFS Server, you should see the message : "DiscordBot Connected" in your LFSLapper console.
This message also appears in the MSS log file. 'Bin/Default/Logs/xxx.xxx.xxx.xxx-yyyyy.LOG' if you do not have access to the console.

#5. To send message from LFSLapper to your Discord Server. You use the function: sendmessagetodiscord();
You can use this function in a command,sub or event.

Here's an example:

$DiscordChannel = "123456789012345457214";
$Message = "This is a test";
sendmessagetodiscord($DiscordChannel,$Message);

#6.1. To send an message from Discord To LFSLapper, you type a message in one of the discord channels
you've set @ step 3.
Those messagew will be executed in the LapperEvent named: OnReceiveDiscordMessage()

Open LFSLapper.LPR in the default folder and look for the event you see below.

Event OnReceiveDiscordMessage($ChannelID,$ChannelName,$UNameID,$UName,$Text)
#Your code
EndEvent

#6.2. Type and place the current line between Event and EndEvent
globalmsg("^3DiscordMsg: ^3".$Text);

#6.3. Write a message in the discordchannel and press enter.
You should see the message, you've written in your discordchannel.

Discord Embed Examples
<?php 
#################################################
#Single Field
#################################################
#DiscordChannel to receive this embed.
$DiscordChannel = "";
#Set Title/Description and color of the discord embed
$Title = "LFSLapper Embed Title";
$Desc = "Embed Description";
#Prefix must contain &#039;0x&#039; Followed by 6 chars 0-9 and A-F
$Color = "0xFF0000"; #RED
#Field Values
## Use %nf% to create a new field. (Add %nf% to $FieldValue and $FieldInline aswell) ##
## The amount of $FieldTitle and $FieldValue and $FieldInLine must be the same. Otherwise you will receive errors.
$FieldTitle = "Field_01 Title";
$FieldValue = "Field_01 Value";
$FieldInline = "True";
#Use %nf% to add a footer image URL !! Not an local(pc) image.
$Footer = "LFSLapper Footer: ".GetLapperVar("ShortTime")." %nf% https://velocitymsports.com/home/vmlogo.png ";
#Small Image URL on the right side of the Embed box.
$ThumbnailUrl = "https://velocitymsports.com/home/vmlogo.png";
#The Entire EmbedBox will fit to the same size as the ImageUrl.
$ImageUrl = "";
#Function to send Discord Embed
SendDiscordEmbed($DiscordChannel,$Title,$Desc,$Color,$FieldTitle,$FieldValue,$FieldInline,$Footer,$ThumbnailUrl,$ImageUrl);

#################################################
#Multiple Fields
#################################################
#DiscordChannel to receive this embed.
$DiscordChannel = "";
#Set Title/Description and color of the discord embed
$Title = "LFSLapper Embed Title";
$Desc = "Embed Description";
#Prefix must contain &#039;0x&#039; Followed by 6 chars 0-9 and A-F
$Color = "0xFF0000"; #RED
#Field Values
## Use %nf% to create a new field. (Add %nf% to $FieldValue and $FieldInline aswell) ##
## The amount of $FieldTitle and $FieldValue and $FieldInLine must be the same. Otherwise you will receive errors.
$FieldTitle =
"Field_01 Title"
."%nf%Field_02 Title"
."%nf%Field_03 Title"
."%nf%Field_04 Title";
$FieldValue =
"*Field_01 Value*\n*Field_01 Value*"
."%nf%Field_02 Value"
."%nf%```New BlockLine_01\nNew BlockLine_02\nNew BlockLine_03\nNew BlockLine_04\nNew BlockLine_05\nNew BlockLine_06\nNew BlockLine_07```"
."%nf%**Field_04 Value**\n**Field_04 Value**\n**Field_04 Value**\n**Field_04 Value**";
$FieldInline = "True%nf%True%nf%False%nf%False";
#Use %nf% to add a footer image URL !! Not an local(pc) image.
$Footer = "LFSLapper Footer: ".GetLapperVar("ShortTime")." %nf% https://velocitymsports.com/home/vmlogo.png ";
#Small Image URL on the right side of the Embed box.
$ThumbnailUrl = "https://velocitymsports.com/home/vmlogo.png";
#The Entire EmbedBox will fit to the same size as the ImageUrl.
$ImageUrl = "";
#Function to send Discord Embed
SendDiscordEmbed($DiscordChannel,$Title,$Desc,$Color,$FieldTitle,$FieldValue,$FieldInline,$Footer,$ThumbnailUrl,$ImageUrl);
?>
Attached images
discordembed1.PNG
This thread is closed

Discord - How To
(2 posts, closed, started )
FGED GREDG RDFGDR GSFDG