Skip to content

Instantly share code, notes, and snippets.

@Luckshya
Last active March 9, 2019 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luckshya/feb5b5755fbabb86e512be62195181f0 to your computer and use it in GitHub Desktop.
Save Luckshya/feb5b5755fbabb86e512be62195181f0 to your computer and use it in GitHub Desktop.
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.");
}
//event onDiscord_Loaded when all the server guilds are loaded
function onDiscord_Loaded(discordHandle) {
//retrieve our connection ID
local connID = Discord_ConnID(discordHandle);
print("Discord bot at ID: " + connID + " has loaded Guilds.");
//send a messsage
Discord_Message(discordConn, "channel ID", "message here"); //you can use discordHandle as well
}
//event onDiscord_Message when a message to recieved to an accessible channel to bot
function onDiscord_Message(discordHandle, channelID, authorID, authorNick, author, roles, message) {
//retrieve our connection ID
local connID = Discord_ConnID(discordHandle);
print("Discord bot at ID: " + connID + " has recieved a message.");
print("ChannelID: " + channelID);
print("Author: " + author);
print("Author Nick: " + authorNick);
print("Author ID: " + authorID);
print("Message: " + message);
foreach(role in roles) {
print("Role: " + role);
print("Role Name: " + Discord_GetRoleName(discordHandle, "server ID", role));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment