C
C#9mo ago
Taha

❔ My discord bot Does work in DMs but servers

Today i wrote a simple C# bot in .NET framework. It Works well in dms but it does not answer my commands in a server(btw im using prefix commands not slash ones)im pretty sure i turned on intents Also while my bot is starting it says "You're using the GuildScheduledEvents gateway intent without listening to any events related to that Gateway. Consider removing the intent from your config" I dont know what that means.
83 Replies
Kotz
Kotz9mo ago
Out of curiosity - is there a reason you're using .NET Framework instead of .NET Core?
mtreit
mtreit9mo ago
There is a #discord-dev channel that might be of help.
Taha
Taha9mo ago
Um no? Kk tysm!
CrumpetMan
CrumpetMan9mo ago
You need to specifically tell the DiscordClient to use the Message intents
Taha
Taha9mo ago
how?
CrumpetMan
CrumpetMan9mo ago
one min let me fire up my project
CrumpetMan
CrumpetMan9mo ago
CrumpetMan
CrumpetMan9mo ago
Add the intents from here
CrumpetMan
CrumpetMan9mo ago
Then start the client from that config
Taha
Taha9mo ago
Ohh tysm! So i make a new method I mean
CrumpetMan
CrumpetMan9mo ago
Share a snippet of your code
Taha
Taha9mo ago
Where of it?
CrumpetMan
CrumpetMan9mo ago
Where you start the client
Taha
Taha9mo ago
I dont have a thing like that in my code
CrumpetMan
CrumpetMan9mo ago
Program.cs?
Taha
Taha9mo ago
Also
CrumpetMan
CrumpetMan9mo ago
What Discord library are you using?
Taha
Taha9mo ago
my _client = new DiscordSocketClieny() the parantes is empty Discord.NET In what method should i add that?
CrumpetMan
CrumpetMan9mo ago
Replace it with this
Taha
Taha9mo ago
Ok tysm!!
CrumpetMan
CrumpetMan9mo ago
Wait not that It's not editing lol
_client = new DiscordSocketClient(new DiscordSocketConfig
{
AlwaysDownloadUsers = true,
MessageCacheSize = 1000,
GatewayIntents = DirectMessages
| DirectMessageTyping
| MessageContent
});
_client = new DiscordSocketClient(new DiscordSocketConfig
{
AlwaysDownloadUsers = true,
MessageCacheSize = 1000,
GatewayIntents = DirectMessages
| DirectMessageTyping
| MessageContent
});
Replace it with this
Taha
Taha9mo ago
Ok i try that! Tysm for help!
CrumpetMan
CrumpetMan9mo ago
np you're on .NET Framework so you need to include parentheses for initialisation:
_client = new DiscordSocketClient(new DiscordSocketConfig()
{
AlwaysDownloadUsers = true,
MessageCacheSize = 1000,
GatewayIntents = DirectMessages
| DirectMessageTyping
| MessageContent
});
_client = new DiscordSocketClient(new DiscordSocketConfig()
{
AlwaysDownloadUsers = true,
MessageCacheSize = 1000,
GatewayIntents = DirectMessages
| DirectMessageTyping
| MessageContent
});
highly suggest you migrate to new .NET versions and upgrade your language version
Taha
Taha9mo ago
Ok! Ty And a problem It does not recognize MessageCacheSize i have no idea why Am i missing a using or smth?
CrumpetMan
CrumpetMan9mo ago
no just remove it Probably has a different name You're running an older version of the library
Taha
Taha9mo ago
So its not necessary?
CrumpetMan
CrumpetMan9mo ago
depends on your bot's functionalities
Taha
Taha9mo ago
I found a class called MessageCache
CrumpetMan
CrumpetMan9mo ago
It's probably that
Taha
Taha9mo ago
But not a field
Kotz
Kotz9mo ago
You should seriously reconsider your choice then, because .NET Framework is on maintenance mode and thus not receiving new features or being worked on anymore.
Taha
Taha9mo ago
Is it supposed to be a class? I know
Kotz
Kotz9mo ago
If you know, then why did you...
Taha
Taha9mo ago
I use .NET 8 most of the time For everything
CrumpetMan
CrumpetMan9mo ago
It's not really necessary but either way you should upgrade Discord.Net to 3.9 because the Discord API changes very often Also please upgrade to .NET 7
Kotz
Kotz9mo ago
.NET 8 is not even released yet
Taha
Taha9mo ago
i mean .NET 7 Sorry Im on 2022 Vs I have to write all my codes again ? I have .net 7 Already
Kotz
Kotz9mo ago
Then you're not using .NET Framework
CrumpetMan
CrumpetMan9mo ago
Can't judge but definitely not all of it Some platform specific stuff will not be supported I think
Taha
Taha9mo ago
My cousin told me to make sure its .net framework
Kotz
Kotz9mo ago
Why?
Taha
Taha9mo ago
Bc he was not used to new thing Discord.net Things
Kotz
Kotz9mo ago
Well, your cousin is a dumbass.
Taha
Taha9mo ago
oh:((
CrumpetMan
CrumpetMan9mo ago
Example of migrating to the latest .NET - .NET
Learn how to migrate your applications from .NET 5, .NET Core, and .NET Framework to .NET 7.
Taha
Taha9mo ago
Am i fucked up now?
CrumpetMan
CrumpetMan9mo ago
No doesn't take more than 30 minutes to migrate in my experience
Taha
Taha9mo ago
I swear i have never used .net framework in my life but this time
Kotz
Kotz9mo ago
There is literally no reason to use .NET Framework for new projects. Some libraries don't even support it anymore. I don't know if that's the case for Discord.Net, but I do know it is for DSharpPlus and Remora.
CrumpetMan
CrumpetMan9mo ago
WinForms, WPF, and UWP cough cough
Kotz
Kotz9mo ago
Those all work on .NET Core.
Taha
Taha9mo ago
So lemme try without that thing The cachesize Btw @OfType<T>()
CrumpetMan
CrumpetMan9mo ago
They're not cross-platform so why would you deploy a self-contained 150mb copy to an end user when you can just do 10mb with .NET Framework?
Taha
Taha9mo ago
Is the massagecachesize a field ??
Kotz
Kotz9mo ago
That's a different discussion.
CrumpetMan
CrumpetMan9mo ago
It is yeah that's my point. I think newer .NET versions should always be shipped with Windows updates
Taha
Taha9mo ago
Ok
Kotz
Kotz9mo ago
So Windows users get 10mb binaries, but other platforms keep getting 60mb ones?
Taha
Taha9mo ago
Ok lets see if it works
CrumpetMan
CrumpetMan9mo ago
last I checked WinForms and WPF are not even cross-platform so
Kotz
Kotz9mo ago
Oh right Fair
Taha
Taha9mo ago
Its connecting NO WAY The error is fixed The error that i said upper But it did not work Wait maybe i should restart it
CrumpetMan
CrumpetMan9mo ago
that was a warning not an error make sure you're not filtering the MessageReceived event
Taha
Taha9mo ago
Okay
CrumpetMan
CrumpetMan9mo ago
_client.MessageReceived += (m) => _ = Task.Run(() => HandleMessageAsync(m));
_client.MessageReceived += (m) => _ = Task.Run(() => HandleMessageAsync(m));
Subscribe to the event like this
private async Task HandleMessageAsync(SocketMessage socketMessage)
{
var argPos = 0;
if (socketMessage.Author.IsBot)
return;

if(socketMessage is not SocketUserMessage message)
return;
...
private async Task HandleMessageAsync(SocketMessage socketMessage)
{
var argPos = 0;
if (socketMessage.Author.IsBot)
return;

if(socketMessage is not SocketUserMessage message)
return;
...
Place breakpoints on your socketMessage. See if its Content property contains any value.
Taha
Taha9mo ago
So where should i put this code I mean what method Oh ok
CrumpetMan
CrumpetMan9mo ago
Where you subscribe to the events
Taha
Taha9mo ago
Look at this @OfType<T>()
private async Task HandleCom(SocketMassege args)
{
var msg = args as SocketUserMassege;
var context = new SocketCommandContext(_client,msg)
if(msg.Author.IsBot)
return;

Int argPos = 0;
If (msg.HasStringPrefix("$" ,ref argPos)
{
Var res = await _command.ExcuteAsync(context,argPos,_services)
If(!res.Issuccses) console.writle(msg.errorreason)
}



}
private async Task HandleCom(SocketMassege args)
{
var msg = args as SocketUserMassege;
var context = new SocketCommandContext(_client,msg)
if(msg.Author.IsBot)
return;

Int argPos = 0;
If (msg.HasStringPrefix("$" ,ref argPos)
{
Var res = await _command.ExcuteAsync(context,argPos,_services)
If(!res.Issuccses) console.writle(msg.errorreason)
}



}
mtreit
mtreit9mo ago
If you're going to share code snippets you should make sure they are not full of typos Did you type that in a word processor?
CrumpetMan
CrumpetMan9mo ago
Place a breakpoint after msg. See if its Content property is null
Taha
Taha9mo ago
I didnt copy that code Im on phone in my discord
CrumpetMan
CrumpetMan9mo ago
$10 typed on a phone crap
mtreit
mtreit9mo ago
💵
CrumpetMan
CrumpetMan9mo ago
I was one second late
Taha
Taha9mo ago
Ok wait Still does not work
CrumpetMan
CrumpetMan9mo ago
obviously that's the whole point of debugging you need to check this
Taha
Taha9mo ago
I tried that
CrumpetMan
CrumpetMan9mo ago
and? Is Content null?
Taha
Taha9mo ago
Wait I searched in google and amd it said smth is wrong with my intent Is that the code which activates the intents?
CrumpetMan
CrumpetMan9mo ago
Yeah
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts