CSharpShellApp
CSharpShellApp copied to clipboard
Discord.Net question
Can I create discord bot with Discord.NET nuget package in your app that works as console or maui app and even the compiled apk works(or there is any workaround to make it work in it, like I am creating bot with only the dependencies of Discord.NET)? I tried with console project.
Exception with compiled apk:
When I want to run in your app the last log says connecting, so I guess it can't connect:
And this is the code:
using System;
using System.Linq; using System.Threading.Tasks; using Discord.Net; using Discord; using Discord.WebSocket;
namespace DiscordBotTest;
public static class Program { public static Task Main(string[] args) { return new MainProgram().Main(); } }
class MainProgram { DiscordSocketClient client;
public async Task Main()
{
string token = "<token>";
client = new DiscordSocketClient();
client.Log += Log;
await client.LoginAsync(TokenType.Bot,token);
await client.StartAsync();
await Task.Delay(-1);
}
private Task Log(LogMessage msg)
{
Console.WriteLine(msg.ToString());
return Task.CompletedTask;
}
}
Please help!
It looks like you haven't added internet permission.
@radimitrov and the VTable exception?
@kovlevi Must have misread the exception that night. Could be that the wrong framework dependencies were being included in the APK. That should be fixed in next update.
@radimitrov It wasn't fixed
@sedoLevi609 Are you sure both the app and plugin are updated?
I haven't created a discord bot, but it looks like it will work since there should be a TypeLoadException at that point too judging by the stack trace.
@radimitrov I updated both. This exception you now got is because I have now another token for a reason by the way. And there is no TypeLoadException anymore.
@radimitrov exception not thrown in compiled apk, but same result as running directly from your app(always wants to connect without success)
If I set LogLevel to debug, one more item is logged: Connecting ApiClient and that's where it's stuck, It's keep tried connecting without success
What could be wrong?
@sedoLevi609 Both in an app / apk and in C# Shell it doesn't throw any Exception but also doesn't connect? At this point it sounds like the URI could be blocked by the system. Possibly server or token configuration
@radimitrov This link may help you(I read it, but since you know how you implemented your app, you perhaps find the problem):
https://discordnet.dev/guides/getting_started/installing.html?tabs=vs-install%2Ccustom-pkg
Please tell me if you find anything in the link that is related to my problem. (and yes, no exception thrown , only for some reason it seems it doesn't connect)
@radimitrov There is any way to debug code with breakpoints in your app? (because I could find the cause of the problem in the downloaded code(from github) of Discord.NET with breakpoints and if I try to fix it, maybe it will work. In worst case i need to try the whole thing with http requests, because discord bot has public rest api, and Discord.NET only uses that)
@sedoLevi609 You could debug like that yes, but it is probably HttpClient related. From your link Discord.Net says they don't officially support Mono and Android runs C# on it. I'm going to have to look into configurations and defaults since I can't find anything useful for .net6/7-android at first glance.
@radimitrov How can I set breakpoint in your app(can't find button or anything)?
@sedoLevi609 Big green "+" circle button, smaller red circle