question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discord Bot Not Logging In!

See original GitHub issue

So just opened a new project and installed Discord.Net so I could create a Discord bot.

But when I ran the program it fires the loggedIn event like normal but the bot is offline and its not responding to commands.

I then use the log event to see whether it was connecting to Discords gateway but no, it just tells me the API version and that’s it.

Here’s my code:

static void Main(string[] args)
{
    new Thread(async () =>
    {
        client.LoggedIn += OnLoggedIn;
        client.MessageReceived += OnMessageReceive;
        client.Log += Client_Log;
        await client.LoginAsync(TokenType.Bot, token);
    }).Start();

    Thread.Sleep(-1);
}

private static Task Client_Log(LogMessage arg)
{
    Console.WriteLine(arg);
    return Task.CompletedTask;
}

static DiscordSocketClient client = new DiscordSocketClient();

static string token = "My token goes here.";

private static Task OnLoggedIn()
{
    Console.WriteLine("logged in.");
    return Task.CompletedTask;
}

private static Task OnMessageReceive(SocketMessage arg)
{
    Console.WriteLine(arg.Content);
    return Task.CompletedTask;
}

Screenshot_3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13

github_iconTop GitHub Comments

2reactions
CodeDiseaseDevcommented, May 19, 2021

it is a library problem!! its still not logging in. and ive made a bot with discord.net before

1reaction
DaNeubicommented, May 20, 2021

You are missing

 await client.StartAsync();

As mentioned in Start making a bot

I would recommend you to use await Task.Delay(-1); as mentioned by @erxkk

Read more comments on GitHub >

github_iconTop Results From Across the Web

Discord.js bot not logging in
It's looking like about the intents and there's simple mistake as i've seen. If you wan't to open all intents i recommend you...
Read more >
Discord bot does not connect with no error messages
My Discord bot (~acolyte-bot) won't login to the discord API. I'm using Discord.js. I have tried: curl -I https://discordapp.com/api/v7/ ...
Read more >
Discord.js bot will not login to client user
So I have a Discord bot, and it's been working just fine. I've had it running for 28 days now, and it's done...
Read more >
Why Are Discord Bots Not Working?
Discord bots may not work for various reasons, such as server issues, hosting problems, code errors, permission issues, or outdated files.
Read more >
Bot unable to login for 24hrs · Issue #5315 · discordjs ...
I'm the owner of a fairly large (~7k guilds) bot using discord.js. I have been using discord.js in production for over a year...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found