Skip to content

Instantly share code, notes, and snippets.

@Luckshya
Luckshya / example.nut
Last active May 15, 2020 16:29
Discord message handler
// Table to hold our Discord CSessions
sessions <- {};
// Wrapper class to manage our session
class CDiscord
{
session = null;
connID = null;
channels = null;
@Luckshya
Luckshya / Example.nut
Created March 10, 2019 10:52
Example discord code for official squirrel plugin (sleepy-discord)
//open connection to discord
discordConn <- Discord_Open("token here");
//event onDiscord_Ready indicating that the bot has connected successfully
function onDiscord_Ready(discordHandle) {
//retrieve our connection ID
local connID = Discord_ConnID(discordHandle);
print("Discord bot at ID: " + connID + " is ready.");
@Luckshya
Luckshya / Example.nut
Last active March 9, 2019 11:47
Example discord code for official squirrel plugin (libdiscord)
//open connection to discord
discordConn <- Discord_Open("token here");
//event onDiscord_Ready indicating that the bot has connected successfully
function onDiscord_Ready(discordHandle) {
//retrieve our connection ID
local connID = Discord_ConnID(discordHandle);
print("Discord bot at ID: " + connID + " is ready.");
}
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);
}
@Luckshya
Luckshya / Example-libdiscord.nut
Last active March 7, 2019 16:24
SqMod Discord Example (libdiscord)
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);