Doesn't seem to work. The severely lacking documentation isn't helpful either.
EDIT: OK, it seems it does get guilds and channels, but Channel.IsText is broken, and so is Channel.GetID.
EDIT2: Updated to the code on GitHub. I can get messages from Discord to the server, but not the other way around. My bot also never shows as "online". When I try to send a message from the server to Discord, I get this message:
PHP Code:
L 06/24/2018 - 01:09:48: [discord_api.smx] [DISCORD] Couldn't Send Message - Fail 0 400
(Error 400 means Bad Request, btw.)
PHP Code:
#pragma semicolon 1
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <discord>
public Plugin myinfo = {
name = "Relay for Discord",
author = "StrikerTheHedgefox",
description = "",
version = PLUGIN_VERSION,
url = ""
};
DiscordBot gBot = null;
char channelID[256] = "FUCK";
public void OnPluginStart() {
//
}
public OnAllPluginsLoaded() {
gBot = new DiscordBot("KEY");
gBot.MessageCheckInterval = 1.0;
gBot.GetGuilds(GuildList);
}
public void GuildList(DiscordBot bot, char[] id, char[] name, char[] icon, bool owner, int permissions, any data) {
//Retrieve all channels for the guild
PrintToChatAll("[DISCORD] Bot in guild: %s\n", name);
bot.GetGuildChannels(id, ChannelList);
}
public void ChannelList(DiscordBot bot, char[] guild, DiscordChannel Channel, any data) {
//Verify that the channel is a text channel
//Get name of channel
char name[32];
Channel.GetName(name, sizeof(name));
PrintToChatAll("[DISCORD] Channel Name: %s\n", name);
//Compare name of channel to 'server-announcement'
if(StrEqual(name, "server-relay", false)) {
//Start listening to channel
bot.StartListeningToChannel(Channel, OnMessage);
Channel.GetID(channelID, sizeof(channelID));
}
}
public void OnMessage(DiscordBot bot, DiscordChannel channel, DiscordMessage message)
{
//Received a message, print it out.
DiscordUser user = message.GetAuthor();
char username[64];
user.GetUsername(username, sizeof(username));
char messagecontent[255];
message.GetContent(messagecontent, sizeof(messagecontent));
PrintToChatAll("\x0700FF00[\x07FFFF00Discord\x0700FF00] \x0700FFFF<\x07FFFFFF%s\x0700FFFF> \x07FFFFFF%s", username, messagecontent);
}
public Action:OnChatMessage(&client, Handle:recipients, String:name[], String:message[])
{
if(!StrEqual(channelID, "FUCK"))
{
char newString[255];
FormatEx(newString, sizeof(newString), "<%s> %s", name, message);
gBot.SendMessageToChannelID(channelID, newString);
}
}