Last active
March 7, 2019 16:24
-
-
Save Luckshya/28b639d297fb17ce8d2f9d5a388fed0b to your computer and use it in GitHub Desktop.
SqMod Discord Example (libdiscord)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyDiscord extends SqDiscord.Session | |
{ | |
function constructor() { | |
// Call the base constructor to intialize the connection | |
base.constructor(); | |
// Bind our events | |
base.Bind(SqDiscordEvent.Ready, this, onReady); | |
base.Bind(SqDiscordEvent.Message, this, onMessage); | |
base.Bind(SqDiscordEvent.GuildLoaded, this, onLoaded); | |
} | |
// Event onReady (Very first event for doing discord related stuff) | |
function onReady() { | |
SqLog.Inf("Dicord bot connection established successfully."); | |
} | |
// Event onLoaded is called when server guilds are loaded | |
function onLoaded() { | |
SqLog.Inf("Loaded Guilds!"); | |
this.Message("channel ID", "message string"); //used to send a message to the specified channel | |
} | |
// Event onMessage is called when a message is recieved to an acessible channel to bot | |
function onMessage(channelID, author, authorNick, authorID, roles, message) { | |
SqLog.Inf("Channel: " + channelID); | |
SqLog.Inf("Author: " + author); | |
SqLog.Inf("Author Nick: " + authorNick); | |
SqLog.Inf("Author ID: " + authorID); | |
SqLog.Inf("Message: " + message); | |
foreach(role in roles) { | |
SqLog.Inf("Role: " + role); | |
SqLog.Inf("Role Name: " + this.GetRoleName("server ID", role)); | |
} | |
} | |
} | |
// Create an instance of our Session | |
myDiscord <- MyDiscord(); | |
// Makes connection to discord | |
myDiscord.Connect("token here"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment