Last active
March 9, 2019 11:47
-
-
Save Luckshya/feb5b5755fbabb86e512be62195181f0 to your computer and use it in GitHub Desktop.
Example discord code for official squirrel plugin (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
//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