I tried a simple plugin to send all chat messages to discord and retrieve chat messages, 0 success, the error:
L 03/13/2018 - 19:50
4: [discord_api.smx] [DISCORD] Couldn't Retrieve Guilds - Fail 0 401
The code:
Code:
#pragma semicolon 1
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <morecolors>
#include <discord>
public Plugin myinfo = {
name = "Announcements from Discord",
author = "Deathknife",
description = "",
version = PLUGIN_VERSION,
url = ""
};
DiscordBot gBot = null;
DiscordChannel gChannel = null;
public void OnPluginStart() {
AddCommandListener(OnChatSent, "say");
}
public Action:OnChatSent(client, String:Command[], args)
{
if(gBot == null || gChannel == null)
return;
char Message[200];
GetCmdArgString(Message, sizeof(Message));
StripQuotes(Message);
if(Message[0] != '/' && Message[0] != '!')
{
char MessageSend[267];
Format(MessageSend, sizeof(MessageSend), "%N: %s", client, Message);
gBot.SendMessage(gChannel, MessageSend);
}
}
public OnAllPluginsLoaded() {
//Create bot with a token
gBot = new DiscordBot("NDIzMTg2NzkwMDUzMDUyNDMy.DYmv2g.wKl067D8hID196rAtFVLLXqZrhs");
//Get all guilds then channels to find any channel with the name of server-announcement
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
bot.GetGuildChannels(id, ChannelList);
}
public void ChannelList(DiscordBot bot, char[] guild, DiscordChannel Channel, any data) {
//Verify that the channel is a text channel
if(Channel.IsText) {
//Get name of channel
char name[32];
Channel.GetName(name, sizeof(name));
//Compare name of channel to 'server-announcement'
if(StrEqual(name, "game-chat", false)) {
//Start listening to channel
bot.StartListeningToChannel(Channel, OnMessage);
gChannel = Channel;
}
}
}
public void OnMessage(DiscordBot Bot, DiscordChannel Channel, const char[] message, const char[] messageID, const char[] userID, const char[] userName, const char[] discriminator) {
//Received a message, print it out.
CPrintToChatAll("{green}[Discord]{normal} %s: %s", userName, message);
}
__________________
I am available to make plugins for pay.
Discord: Eyal282#1334