discord-net / Discord.Net

An unofficial .Net wrapper for the Discord API (https://discord.com/)
https://discordnet.dev
MIT License
3.33k stars 736 forks source link

[Not A Bug, Never Mind]: Message content is now BLANK from Client_MessageReceived(SocketMessage MsgParam) (edit: GatewayIntents.MessageContent added in 3.8.0 in DiscordSocketConfig) #2474

Closed DeSinc closed 2 years ago

DeSinc commented 2 years ago

EDIT: GatewayIntents.MessageContent was added to DiscordSocketConfig in 3.8.0 or 3.8.1 as below:

Client = new DiscordSocketClient(new DiscordSocketConfig
                {
                    MessageCacheSize = 1200,
                    LogLevel = LogSeverity.Debug,
                    AlwaysDownloadUsers = true,
                    GatewayIntents =
                GatewayIntents.MessageContent |    <--- Add this one to your code
                GatewayIntents.GuildPresences |
                GatewayIntents.Guilds |
                GatewayIntents.GuildMembers |
                GatewayIntents.GuildMessageReactions |
                GatewayIntents.GuildMessages |
                GatewayIntents.GuildVoiceStates
                });

Check The Docs

^ to be fair it was in the docs.. it's just I didn't know where to search to find out that that new line was required

Verify Issue Source

Check your intents

Description

Message content is totally blank in 3.8.1 (I have not tested 3.8.0) but it works fine in 3.7.2.

private async Task Client_MessageReceived(SocketMessage MsgParam)
        {
            var Msg = MsgParam as SocketUserMessage;

                Console.WriteLine(Msg);
                Console.WriteLine("ToString() below:");
                Console.WriteLine(MsgParam.CleanContent);
                Console.WriteLine(Msg.Content.ToString());
        }

All of the above WriteLines just send blank content. Only change made is the API updated to the latest 3.8.1 version.

Previous versions all still work with the same code shown here.

Commands are all broken due to this as message content is unreadable. All spam filtering is broken due to not being able to parse the message.

Version

3.8.1

Working Version

3.7.2

Logs

Not sure what a stack trace is but thankfully I don't believe it's necessary for this bug.

Sample

private async Task Client_MessageReceived(SocketMessage MsgParam)
        {
            var Msg = MsgParam as SocketUserMessage;

                Console.WriteLine(Msg);
                Console.WriteLine("ToString() below:");
                Console.WriteLine(MsgParam.CleanContent);
                Console.WriteLine(Msg.Content.ToString());
        }

Packages

Discord.Net.Core Discord.Net.WebSocket Discord.Net.Commands

Misha-133 commented 2 years ago

You need to enable MessageContent intent on dev portal and in DiscordSocketConfig in your code

DeSinc commented 2 years ago

You need to enable MessageContent intent on dev portal and in DiscordSocketConfig in your code

Both are already done. I ticked the intents box because I did check they are all on. I have the code you're referring to already in my bot too, otherwise it would never have worked in the first place:

Client = new DiscordSocketClient(new DiscordSocketConfig
                {
                    MessageCacheSize = 1200,
                    LogLevel = LogSeverity.Debug,
                    AlwaysDownloadUsers = true,
                    GatewayIntents =
                GatewayIntents.GuildPresences |
                GatewayIntents.Guilds |
                GatewayIntents.GuildMembers |
                GatewayIntents.GuildMessageReactions |
                GatewayIntents.GuildMessages |
                GatewayIntents.GuildVoiceStates
                });
Misha-133 commented 2 years ago

But you're missing the GatewayIntents.MessageContent intent

DeSinc commented 2 years ago

But you're missing the GatewayIntents.MessageContent intent

Oh, okay I see what you mean - I thought you could have been referring to something like that but I didn't know what you meant, or that there was a new field.

Just added that new thing in and it works again now in 3.8.1. Thanks! Issue fixed.

Found it in the docs - it's listed here as one of the fields you can provide: https://discordnet.dev/api/Discord.GatewayIntents.html

I suspect this may catch a few people as I wasn't able to really know what I needed to be looking for, but I guess that's just a documentation issue with me generally