-
Notifications
You must be signed in to change notification settings - Fork 1
ExampleCode.1
Luckshya edited this page Jul 9, 2020
·
1 revision
sessions <- {};
class MyDiscord
{
eventFuncs = null;
session = null;
connID = null;
function constructor()
{
session = SqDiscord.CSession();
connID = session.ConnID;
sessions.rawset(connID, this);
eventFuncs = [
onReady,
onMessage,
onError,
onDisconnect,
onQuit
];
session.InternalCacheEnabled = true;
}
function Connect(token)
{
session.Connect(token);
}
function sendMessage(channelID, message)
{
session.Message(channelID, message);
}
function sendEmbed(channelID, embed)
{
session.MessageEmbed(channelID, "", embed);
}
function onReady() {
print("Discord bot connection established successfully.");
}
function onMessage(message) {
print("OnMessage");
local member = message.Member;
local serverID = message.ServerID;
if(member != null && serverID != null) {
foreach(roleID in member.Roles) {
print(session.GetRoleName(serverID, roleID));
}
}
}
function onError(code, message) {
print(format("%d - %s", code, message));
}
function onDisconnect() {
print("Discord session has disconnected.");
}
function onQuit() {
print("Discord session has quit.")
}
}
myDiscord <- MyDiscord();
myDiscord.Connect("token here");
function onDiscordUpdate(connID, eventType, ...) {
if(sessions.rawin(connID)) {
local session = sessions.rawget(connID);
vargv.insert(0, session); //env
session.eventFuncs[eventType].acall(vargv);
}
}