Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SqMod Discord Example (libdiscord)
class MyDiscord extends SqDiscord.Session
function constructor() {
// Call the base constructor to intialize the connection
// 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