PHP Code:
/* Code taken from Discord Server Manager of Nexd */
#include <sourcemod>
#include <multicolors>
#include <discord>
#define ChatRelayChannelID ""
#define BOT_TOKEN ""
#define DiscordTag "[DISCORD]"
DiscordBot Bot;
public void OnConfigsExecuted()
{
KillBot();
CreateBot();
}
public void GuildList(DiscordBot bawt, char[] id, char[] name, char[] icon, bool owner, int permissions, const bool listen)
{
Bot.GetGuildChannels(id, ChannelList, INVALID_FUNCTION, listen);
}
public void ChannelList(DiscordBot bawt, const char[] guild, DiscordChannel Channel, const bool listen)
{
if(StrEqual(BOT_TOKEN, "") || StrEqual(ChatRelayChannelID, ""))
{
return;
}
char id[20];
Channel.GetID(id, sizeof(id));
if(strlen(ChatRelayChannelID) > 10)
{
if(StrEqual(id, ChatRelayChannelID))
{
if(Bot.IsListeningToChannel(Channel))
{
Bot.StopListeningToChannel(Channel);
}
Bot.StartListeningToChannel(Channel, ChatRelayReceived);
}
}
}
public void ChatRelayReceived(DiscordBot bawt, DiscordChannel channel, DiscordMessage discordmessage)
{
if(discordmessage.GetAuthor().IsBot()) return;
char message[512];
char userName[32], discriminator[6];
discordmessage.GetContent(message, sizeof(message));
discordmessage.GetAuthor().GetUsername(userName, sizeof(userName));
discordmessage.GetAuthor().GetDiscriminator(discriminator, sizeof(discriminator));
CPrintToChatAll("%s{purple} %s#%s{default}: %s", DiscordTag, userName, discriminator, message);
}
stock void CreateBot(bool guilds = true, bool listen = true)
{
if(StrEqual(BOT_TOKEN, "") || StrEqual(ChatRelayChannelID, ""))
{
return;
}
Bot = new DiscordBot(BOT_TOKEN);
if(guilds)
{
Bot.GetGuilds(GuildList, _, listen);
}
}
stock void KillBot()
{
delete Bot;
}
Code:
L 07/02/2020 - 09:14:14: [SM] MEMORY LEAK DETECTED IN PLUGIN (file "thisplugin")
L 07/02/2020 - 09:14:14: [SM] Unloading plugin to free 14593 handles.
L 07/02/2020 - 09:14:14: [SM] Contact the author(s) of this plugin to correct this error.
L 07/02/2020 - 09:14:14: --------------------------------------------------------------------------
L 07/02/2020 - 09:14:14: Type DataPack | Count 35
L 07/02/2020 - 09:14:14: Type CellArray | Count 35
L 07/02/2020 - 09:14:14: Type JanssonObject | Count 14523
L 07/02/2020 - 09:14:14: -- Approximately 1260 bytes of memory are in use by (14593) Handles.
L 07/02/2020 - 09:14:14: [SM] Exception reported: Memory leak
L 07/02/2020 - 09:14:14: [SM] Blaming: discord_api.smx
L 07/02/2020 - 09:14:14: [SM] Call stack trace:
L 07/02/2020 - 09:14:14: [SM] [0] json_object_get
L 07/02/2020 - 09:14:14: [SM] [1] Line 18, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/stocks.inc::JsonObjectGetString
L 07/02/2020 - 09:14:14: [SM] [2] Line 23, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/channel.inc::DiscordChannel.GetID
L 07/02/2020 - 09:14:14: [SM] [3] Line 68, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/bot.inc::DiscordBot.IsListeningToChannelID
L 07/02/2020 - 09:14:14: [SM] [4] Line 106, discord/ListenToChannel.sp::OnGetMessage_Data
L 07/02/2020 - 09:14:14: [SM] [6] SteamWorks_GetHTTPResponseBodyCallback
L 07/02/2020 - 09:14:14: [SM] [7] Line 74, discord/ListenToChannel.sp::OnGetMessage
L 07/02/2020 - 09:14:14: [SM] Exception reported: Could not create <Object> handle.
L 07/02/2020 - 09:14:14: [SM] Blaming: discord_api.smx
L 07/02/2020 - 09:14:14: [SM] Call stack trace:
L 07/02/2020 - 09:14:14: [SM] [0] json_object_get
L 07/02/2020 - 09:14:14: [SM] [1] Line 18, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/stocks.inc::JsonObjectGetString
L 07/02/2020 - 09:14:14: [SM] [2] Line 23, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/channel.inc::DiscordChannel.GetID
L 07/02/2020 - 09:14:14: [SM] [3] Line 68, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/bot.inc::DiscordBot.IsListeningToChannelID
L 07/02/2020 - 09:14:14: [SM] [4] Line 106, discord/ListenToChannel.sp::OnGetMessage_Data
L 07/02/2020 - 09:14:14: [SM] [6] SteamWorks_GetHTTPResponseBodyCallback
L 07/02/2020 - 09:14:14: [SM] [7] Line 74, discord/ListenToChannel.sp::OnGetMessage
Any heads up would be appreciated. Every thing works though.
Edit: This is just snippet of whole code. This issue comes up only when using this part of code so...
Edit2: This fixed the issue again took help from nexd's plugin xd
Code:
stock void KillBot()
{
if(Bot)
{
Bot.StopListeningToChannels();
Bot.StopListening();
}
delete Bot;
}
__________________