View Single Post
StrikerMan780
AlliedModders Donor
Join Date: Jul 2009
Location: Canada
Old 06-23-2018 , 23:42   Re: [ANY] Discord API (Send/Retrieve messages, list Guilds/Channels) UPDATE: 10/1/17
Reply With Quote #35

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] [DISCORDCouldn'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 botchar[] idchar[] namechar[] iconbool ownerint permissionsany data) {
    
//Retrieve all channels for the guild
    
PrintToChatAll("[DISCORD] Bot in guild: %s\n"name);
    
bot.GetGuildChannels(idChannelList);
}

public 
void ChannelList(DiscordBot botchar[] guildDiscordChannel Channelany data) {
    
//Verify that the channel is a text channel
    
    //Get name of channel
    
char name[32];
    
Channel.GetName(namesizeof(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(ChannelOnMessage);
        
Channel.GetID(channelIDsizeof(channelID));
    }
}

public 
void OnMessage(DiscordBot botDiscordChannel channelDiscordMessage message)
{
    
//Received a message, print it out.
    
DiscordUser user message.GetAuthor();
    
char username[64];
    
user.GetUsername(usernamesizeof(username));
    
char messagecontent[255];
    
message.GetContent(messagecontentsizeof(messagecontent));
    
    
PrintToChatAll("\x0700FF00[\x07FFFF00Discord\x0700FF00] \x0700FFFF<\x07FFFFFF%s\x0700FFFF> \x07FFFFFF%s"usernamemessagecontent);
}

public 
Action:OnChatMessage(&clientHandle:recipientsString:name[], String:message[])
{
    if(!
StrEqual(channelID"FUCK"))
    {
        
char newString[255];
        
FormatEx(newStringsizeof(newString), "<%s> %s"namemessage);
        
gBot.SendMessageToChannelID(channelIDnewString);
    }


Last edited by StrikerMan780; 06-24-2018 at 02:12.
StrikerMan780 is offline