[Bug]: Can't use Bearer token Login after v3.1.0
Check The Docs
- [X] I double checked the docs and couldn't find any useful information.
Verify Issue Source
- [X] I verified the issue was caused by Discord.Net.
Check your intents
- [X] I double checked that I have the required intents.
Description
After upgrading from v3.1.0. I've started receiving Exception when using the Bearer token to Login.
Version
3.7.2
Working Version
3.1.0
Logs
Gateway: System.Exception: Processing READY failed
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Discord.WebSocket.DiscordSocketClient.ProcessMessageAsync(GatewayOpCode opCode, Nullable`1 seq, String type, Object payload)
--- End of inner exception stack trace ---
at Discord.ConnectionManager.WaitAsync()
at Discord.WebSocket.DiscordSocketClient.OnConnectingAsync()
at Discord.ConnectionManager.ConnectAsync(CancellationTokenSource reconnectCancelToken)
at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
Sample
using Discord;
using Discord.Commands;
using Discord.WebSocket;
internal class Startup
{
private readonly String dateFormat = @"yyyy-MM-dd";
private readonly String timeFormat = @"hh:mm:ss.fffffff";
private readonly String _logDirectory;
private readonly String _logFile;
private String[] args;
public Startup(String[] args)
{
this.args = args;
_logDirectory = Path.Combine(AppContext.BaseDirectory, "logs");
_logFile = Path.Combine(_logDirectory, $"{DateTime.UtcNow.ToString(dateFormat)}.txt");
}
internal async Task RunAsync()
{
var discordSocketClient = new DiscordSocketClient(new DiscordSocketConfig
{
LogLevel = LogSeverity.Verbose,
MessageCacheSize = 1000
});
var commandService = new CommandService(new CommandServiceConfig
{
LogLevel = LogSeverity.Verbose,
DefaultRunMode = RunMode.Async
});
discordSocketClient.MessageReceived += OnMessageReceivedAsync;
discordSocketClient.Log += OnLogAsync;
commandService.Log += OnLogAsync;
await discordSocketClient.LoginAsync(TokenType.Bearer, @"XXX");
await discordSocketClient.StartAsync();
// Keep the application alive
await Task.Delay(-1);
}
private Task OnLogAsync(LogMessage msg)
{
if (!Directory.Exists(_logDirectory)) // Create the log directory if it doesn't exist
Directory.CreateDirectory(_logDirectory);
if (!File.Exists(_logFile)) // Create today's log file if it doesn't exist
File.Create(_logFile).Dispose();
string logText = $"{DateTime.UtcNow.ToString(timeFormat)} [{msg.Severity}] {msg.Source}: {msg.Exception?.ToString() ?? msg.Message}";
File.AppendAllText(_logFile, logText + "\n"); // Write the log text to a file
return Console.Out.WriteLineAsync(logText); // Write the log text to the console
}
private async Task OnMessageReceivedAsync(SocketMessage s)
{
}
}
Packages
Discord.Net V3.7.2
We dont support selfbots.
To the above, bearer does not imply self-botting, this is an irrelevant comment.
Could you go further into your use case, so I can attempt to repro?
May be related to #2381
Please follow up on the question above.
Hi, sorry, for the late reply, I was on vacation and forgot about it...
Regarding use-case: I was using it as an alternative to SignalR and developing the additional application (e.g. Guest comes to a Restaurant, joins Discord channel over QR code provided on that table, and calls waiter to his table...waiter can easily reply and owner can have some statistics regarding efficiency, favorite orders etc.) In the meantime, I've switched to TokenType.Bot and managed to solve my problem. I've used Bearer out of laziness (It's Standard and I didn't give too much thought about it + I didn't want to create and Setup a Bot Application) Didn't even know about selfbots before @Pusheon mentioned it so thx for the heads-up!
Regarding #2381 : It could be related, but mine was failing at Login, not at Calling other methods afterward (I'm not calling any except StartAsync) You should be able to reproduce the Bug with the Sample code I've provided above (You can remove logging to the file, shouldn't make any difference).
As I've mentioned v3.1.0 was working fine (except UserMessage didn't contain Content which was the reason why I've updated to v3.7.2), but all later versions were throwing the exception.
Hope that helps, be free to ask if you need any more information.
Ran into this as well. My use case is to register as applications rather than a bot and read from the gateway. Logging in as an application is only possible using a bearer token.