Reputation: 73
Hey folks,
long story short : I've written this line of code in my C# Console-Program
private async Task ClientOnMessageReceived(SocketMessage socketMessage)
{
if (!socketMessage.Author.IsBot)
{
var channel_msg = _client.GetChannel(Convert.ToUInt64(_channelIdSky2)) as SocketTextChannel;
var discordMessages = await channel_msg.GetMessagesAsync(20).FlattenAsync();
var orderedMessages = discordMessages.OrderBy(x => x.Timestamp);
var sb = new StringBuilder();
foreach (var msg in orderedMessages)
{
sb.AppendLine(msg.Author + ":\r\n" + msg.Content + "\r\n");
}
Console.WriteLine(sb.ToString());
}
return;
}
I am getting the following Ouput :
Why the Script can only read Bot Messages and no user messages?
if (!socketMessage.Author.IsBot)
isn't the error. i've tried it without
Would really hope for Your help.
Best greetings from Germany
CMeow
Upvotes: 2
Views: 2734
Reputation: 2658
Make sure that you enable the Message Content Intent on the Discord Developer Portal, because it is a privileged intent and needs to be explicitly set.
Additionally, you need to go into your DiscordSocketConfig
and add the MessageContent
intent to the GatewayIntents
property. If you don't have a DiscordSocketConfig
, create one and pass it into the constructor of your DiscordSocketClient
.
Example:
var config = new DiscordSocketConfig
{
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent
} };
Note: You should specify the intents you actually need instead of defaulting to
All
orAllUnprivileged
Upvotes: 5