Skip to content

Commit

Permalink
Add gateway intent for reading messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ubre committed Apr 2, 2024
1 parent dc14a3e commit 49fbc49
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions FishBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ class Program

public static async Task Main()
{
var _config = new DiscordSocketConfig { MessageCacheSize = 100 };
var _config = new DiscordSocketConfig
{
MessageCacheSize = 100,
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent
};
_client = new DiscordSocketClient(_config);

_client.Log += Log;
_client.MessageUpdated += MessageUpdated;
_client.MessageReceived += MessageReceived;

// You can assign your bot token to a string, and pass that in to connect.
// This is, however, insecure, particularly if you plan to have your code hosted in a public repository.
Expand All @@ -37,7 +42,16 @@ private static Task Log(LogMessage msg)
Console.WriteLine(msg.ToString());
return Task.CompletedTask;
}


private static async Task MessageReceived(SocketMessage message)

Check warning on line 46 in FishBot/Program.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 46 in FishBot/Program.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// Ensure we don't process system messages
if (message is not SocketUserMessage userMessage)
return;

Console.WriteLine($"{userMessage.Author}: {userMessage.Content}");
}

private static async Task MessageUpdated(Cacheable<IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel)
{
// If the message was not in the cache, downloading it will result in getting a copy of `after`.
Expand Down

0 comments on commit 49fbc49

Please sign in to comment.