Discord.Net Docs
Discord.Net's clients provide a log event that all messages will be
dispatched over.
1 messages · Page 1 of 1 (latest)
Discord.Net's clients provide a log event that all messages will be
dispatched over.
This actually comes through the logging event
anytime a message i have sent
in a channel
well anyone.
My other issue i had is archived which was the gate way intents which was fixed but now this has came along
no code changed after the gateway intents fix and this bug
@lucid pagoda @wild bronze lets move it in here
thank you
so errors can come through
but no exception is in the arguement
when it gets logged
I don’t wanna!!!!
stares
Because it’s not an exception?
i know just showing theres no other error with it
it just logs that and does nothing
Do you have an event handler for message created?
What is the logic for your handlecommandasync?
/// <summary>
/// Handle Command Async
/// </summary>
private async Task HandleCommandAsync(SocketMessage arg)
{
try
{
CheckForNewGuilds();
if (arg is SocketUserMessage && arg != null)
{
try
{
var message = arg as SocketUserMessage;
var textchannel = arg.Channel as SocketTextChannel;
if (textchannel != null)
{
ulong guildid = textchannel.Guild.Id;
int argPos = 0;
if (m_GuildsPrefix.ContainsKey(guildid))
{
bool doesNotHaveCharPrefix = !(message.HasCharPrefix(m_GuildsPrefix[guildid], ref argPos));
bool hasUserentioned = message.HasMentionPrefix(m_Client.CurrentUser, ref argPos);
bool isBot = message.Author.IsBot;
if (doesNotHaveCharPrefix || hasUserentioned || isBot)
return;
var context = new SocketCommandContext(m_Client, message);
await m_Commands.ExecuteAsync(
context: context,
argPos: argPos,
services: m_ServiceProvider);
}
}
}
catch (Exception e)
{
DiscordWorker.Log(string.Format("Error occured Handling Message:\r\n" +
"Error: {0}", e.Message), LogType.Error);
}
}
}
catch(Exception e)
{
DiscordWorker.Log($"Error Handling Command {e.Message}", LogType.Error);
}
return;
}
/// <summary>
/// Check for New Guilds
/// </summary>
private void CheckForNewGuilds()
{
KeyValuePair<ulong, char> newguild;
if (m_NewGuilds.Count > 0 && m_NewGuilds.TryDequeue(out newguild))
{
m_GuildsPrefix.Add(newguild.Key, newguild.Value);
}
}
Oof. I’m on mobile. Give me a min to hop on pc.
thank you appreciate it
why sockettextchannel and not socketguildchannel?
I am quite new still to the library
it never had a problem before hm
textchannel inherits it anyway
if that comes out as null, execution stops. which i think you intend. but i've not looked into forum channels and the other new types to know if that will always be NOT null in a channel a user can message in
forum is separate from text channel
are you sending the message in a forum channel?
anytime anyone messages
it just sends
doesntevent get to handling the command it just does the discord log
the "handling message" is never sent?
can we see your startup code? as in initializing the class that HandleCommandAsync resides in?
ye
ofcourse
public async Task Initialize(IServiceCollection serviceprovider)
{
m_ServiceProvider = serviceprovider;
DiscordWorker.Log(string.Format("Initializing Bot"), LogType.Info);
m_BotCommandService = new CommandService(new CommandServiceConfig { DefaultRunMode = RunMode.Async });
m_BotCommandService.Log += LogHandlerAsync;
//
// Init Client
//
var config = new DiscordSocketConfig
{
AlwaysDownloadUsers = false,
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent
};
m_SocketClient = new DiscordSocketClient(config);
m_SocketClient.Log += Log;
m_SocketClient.Connected += Connected;
m_SocketClient.JoinedGuild += BotJoinedGuild;
await m_SocketClient.LoginAsync(TokenType.Bot, m_DiscordToken);
await m_SocketClient.StartAsync();
//
// Handles Logging Messages
//
MessageHandler.Initialise(m_SocketClient);
}
once the bot connected and the event connected is called
//
// Init CommandHandler
//
DiscordWorker.Log("Initialising Commands", LogType.Info);
m_BotCommandHandler = new CommandHandler(m_SocketClient, m_BotCommandService, m_ServiceProvider.BuildServiceProvider(), guildprefixes);
await m_BotCommandHandler.InstallCommandsAsync();
this is ran
it connects etc
where is HandleCommandAsync called?
/// <summary>
/// Install Commands Async
/// </summary>
/// <returns></returns>
public async Task InstallCommandsAsync()
{
m_Client.MessageReceived += HandleCommandAsync;
// Add Modules Here
await m_Commands.AddModulesAsync(assembly: Assembly.GetExecutingAssembly(), services: m_ServiceProvider);
}
I see 2 mins
public async Task Initialize(IServiceCollection serviceprovider)
{
m_ServiceProvider = serviceprovider;
DiscordWorker.Log(string.Format("Initializing Bot"), LogType.Info);
m_BotCommandService = new CommandService(new CommandServiceConfig { DefaultRunMode = RunMode.Async });
m_BotCommandService.Log += LogHandlerAsync;
//
// Init Client
//
var config = new DiscordSocketConfig
{
AlwaysDownloadUsers = false,
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent
};
m_SocketClient = new DiscordSocketClient(config);
m_SocketClient.Log += Log;
m_SocketClient.Connected += Connected;
m_SocketClient.JoinedGuild += BotJoinedGuild;
await m_SocketClient.LoginAsync(TokenType.Bot, m_DiscordToken);
await m_SocketClient.StartAsync();
//
// Handles Logging Messages
//
MessageHandler.Initialise(m_SocketClient);
}
This is called first
what is MessageHandler?
nothing ignore it
is "Initializing Commands" ever sent to console?
if you put a breakpoint on this:
m_Client.MessageReceived += HandleCommandAsync;
is it hit? and is m_client not null?
no its not null i have a try catch that will log any issues with this
i dont think try/catch will show anything for internal nested tasks
honestly, it sounds like an issue with your event sub never being hit.
public async Task InstallCommandsAsync()
{
if (m_Client != null)
{
try
{
m_Client.MessageReceived += HandleCommandAsync;
// Add Modules Here
await m_Commands.AddModulesAsync(assembly: Assembly.GetExecutingAssembly(), services: m_ServiceProvider);
}
catch (Exception e)
{
DiscordWorker.Log($"Error setting up modules: {e.Message}", LogType.Error);
}
}
else
{
DiscordWorker.Log("Client not found", LogType.Error);
}
}
would this break anything?
i... dont know. i've not playing with the locale stuff yet
try putting a Console.Writeline() right after the AddModulesAsync line, to confirm that all above it has been run
I use a debug only logger in development. If the exe was built in debug mode, i get a ton of logging. if built as release, they're all skipped.
try
{
m_Client.MessageReceived += HandleCommandAsync;
// Add Modules Here
await m_Commands.AddModulesAsync(assembly: Assembly.GetExecutingAssembly(), services: m_ServiceProvider);
DiscordWorker.Log("Modules have been added", LogType.Info);
}
catch (Exception e)
{
DiscordWorker.Log($"Error setting up modules: {e.Message}", LogType.Error);
}
ok. that confirms that the event sub was passed.
something is breaking between that point, and when it receives its first message.
yes my handlecommandasyc is never called
you dont have client.messagereceived -= HandleCommandAsync anywhere, do you?
what is the difference between m_client and m_socketclient?
/// <summary>
/// Install Commands Async
/// </summary>
/// <returns></returns>
public async Task InstallCommandsAsync()
{
if (m_SocketClient != null)
{
try
{
m_SocketClient.MessageReceived += HandleCommandAsync;
// Add Modules Here
await m_Commands.AddModulesAsync(assembly: Assembly.GetExecutingAssembly(), services: m_ServiceProvider);
DiscordWorker.Log("Modules have been added", LogType.Info);
}
catch (Exception e)
{
DiscordWorker.Log($"Error setting up modules: {e.Message}", LogType.Error);
}
}
else
{
DiscordWorker.Log("Client not found", LogType.Error);
}
}
my naming isnt consistent
😅
but they are in fact the same client object?
🤔
i havent seen anything in the code you've shown so far, that would stand out as causing the issue. Without seeing the rest of the code, i'm limited to some assumptions.
i know its infuriating
just tell me im shit and find the problem
I literally had the message intent enabling config issue the othe rweek
fixed it
no other issues for a week
then it just breaks
it does not know the channel
so is it not to do with downloading the channels
forwhatever reason
only thing i can think of is that you have two different clients in your code somehow. and the wrong one is having the event subscribed to.
they are both the same
your bot has permission to read the messages?
DiscordBot is what creates the socketclient
/// <summary>
/// Main Async
/// </summary>
/// <returns></returns>
public async Task Initialize(IServiceCollection serviceprovider)
{
m_ServiceProvider = serviceprovider;
DiscordWorker.Log(string.Format("Initializing Bot"), LogType.Info);
m_BotCommandService = new CommandService(new CommandServiceConfig { DefaultRunMode = RunMode.Async });
m_BotCommandService.Log += LogHandlerAsync;
//
// Init Client
//
var config = new DiscordSocketConfig
{
AlwaysDownloadUsers = false,
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent
};
m_SocketClient = new DiscordSocketClient(config);
m_SocketClient.Log += Log;
m_SocketClient.Connected += Connected;
m_SocketClient.JoinedGuild += BotJoinedGuild;
await m_SocketClient.LoginAsync(TokenType.Bot, m_DiscordToken);
await m_SocketClient.StartAsync();
//
// Handles Logging Messages
//
MessageHandler.Initialise(m_SocketClient);
}
This is where socket client is being created and event handles added
what is calling CommandHandler?
on connected
for the socketclient event
/// <summary>
/// Connected Event
/// </summary>
private async Task Connected()
{
if (!m_Initialized)
{
m_Initialized = true;
DiscordWorker.Log("CONNECTED BOT!", LogType.Info);
try
{
await GetGuildsAsync();
}
catch (Exception e)
{
DiscordWorker.Log("Error Establishing Guilds: " + e.Message, LogType.Error);
}
}
}
this is the mothed.
i dont see a call to CommandHandler....
/// <summary>
/// Get Guilds Async
/// </summary>
private async Task GetGuildsAsync()
{
List<GuildItem> guilds = new List<GuildItem>();
Dictionary<ulong, char> guildprefixes = new Dictionary<ulong, char>();
try
{
// guild code
}
catch(Exception e)
{
DiscordWorker.Log($"Error: {e.Message}", LogType.Error);
}
//
// Init CommandHandler
//
DiscordWorker.Log("Initialising Commands", LogType.Info);
m_BotCommandHandler = new CommandHandler(m_SocketClient, m_BotCommandService, m_ServiceProvider.BuildServiceProvider(), guildprefixes);
try
{
await m_BotCommandHandler.InstallCommandsAsync();
}
catch (Exception e)
{
DiscordWorker.Log($"Error installing commands: {e.Message}", LogType.Error);
}
}
the GetGuildsAsync
ah. ok.
public async Task InstallCommandsAsync()
{
if (m_SocketClient != null)
{
try
{
m_SocketClient.MessageReceived += HandleCommandAsync;
// Add Modules Here
await m_Commands.AddModulesAsync(assembly: Assembly.GetExecutingAssembly(), services: m_ServiceProvider);
DiscordWorker.Log("Modules have been added", LogType.Info);
}
catch (Exception e)
{
DiscordWorker.Log($"Error setting up modules: {e.Message}", LogType.Error);
}
}
else
{
DiscordWorker.Log("Client not found", LogType.Error);
}
}
Then we see the log here that confirms the modules being added
and all i get told is the channel is unknown in the message_crate intent
i have no idea
maybe change the topic here from "unknown channel" to "messages not received"?
Message Not Received in CommandHandler
its a gateway problem
the log says
i wonder if its a firewall issue
but it retrieves the channel id
in the log
but must have 0 clue what the guild is it seems
that it is in
to be fair, this is my logging right now, and my bot is working fine...
the bit at the bottom is me pinging the bot
so these actualy log
whatever you call it
trying pinging the bot, and see if that hits the logging message in your handler
sorry how do i do that
@bot_name_here
i honestly dont know then.
still thinking that there's an issue with the event sub for MessageReceived
ye
you're certain that the MessageContent intent is still on in the bot portal for this bot?
@lucid pagoda
so that guild available
gets the data on the guild
and because it was throwing that error
it never gets the data
so when people send message
with the channel id
it has 0 clue what the guild is
as that event has crashed
=====================Solved=====================
If there is any error within the GUILD_AVAILABLE gateway intent. The bot will not receive the information on the guilds it is in. There for message handling will not work.