Discord bot throwing login errors after updating discord.py library - token authentication failing

I’m getting authentication errors with my Discord bot after trying to upgrade discord.py for slash commands support. The bot worked fine before the update but now it won’t start.

Here’s my current bot code:

import discord
from discord.ext import commands

from config import *

bot = commands.Bot(command_prefix=['?', '!', '#', '%', '@'])


@bot.event
async def on_ready():
    print('Bot is online!')
    print('==================')


@bot.event
async def greet(ctx):
    await ctx.send('Hi there!')


@bot.event
async def on_member_join(member):
    with open('welcome_image.png', 'rb') as img:
        welcome_pic = discord.File(img)
        welcome_channel = bot.get_channel(123456789012345678)
        await welcome_channel.send('Welcome! Here is something for you!', file=welcome_pic)


@bot.event
async def farewell(ctx):
    await ctx.send('See you later!')


@bot.event
async def explode(ctx):
    with open('boom.gif', 'rb') as animation:
        boom_gif = discord.File(animation)
    await ctx.send('BOOM TIME!!!', file=boom_gif)


bot.run(TOKEN)

The error I keep getting shows:

Traceback (most recent call last):
  File "discord/http.py", line 349, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "discord/http.py", line 302, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "main.py", line 35, in <module>
    bot.run(TOKEN)
  File "discord/client.py", line 631, in run
    return future.result()
  File "discord/client.py", line 573, in start
    await self.login(*args)
  File "discord/client.py", line 424, in login
    await self.http.static_login(token.strip())
  File "discord/http.py", line 353, in static_login
    raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.

I’m pretty new to Python and this error output is really scary. The bot was working yesterday but after trying to update discord.py it completely broke. Do I need to reinstall the library or is there something wrong with my code? Any help would be great!

This looks like a token authentication problem, not your code. Discord.py’s recent upgrade might need different intents or stricter token validation now.

First, regenerate your bot token in the Discord Developer Portal - tokens sometimes break after library updates. Also check that your TOKEN variable in config.py doesn’t have extra spaces or weird characters.

I hit the same authentication issues when I upgraded. Adding explicit intents fixed it for me. Try this:

intents = discord.Intents.default()
bot = commands.Bot(command_prefix=['?', '!', '#', '%', '@'], intents=intents)

That solved my authentication errors during the transition.

check if you accidentally updated to discord.py v2.x - that version requires intents by default and breaks older code. try downgrading with pip install discord.py==1.7.3 if you don’t need the new features yet. also make sure your token doesn’t have 'Bot ’ prefix in the config file, some people add that by mistake.

Your “Improper token has been passed” error usually means Discord isn’t getting the token it expects. Check that your config.py actually has the right token string and isn’t throwing any import errors. Print the TOKEN variable right before bot.run() to see what’s actually loading. Sometimes library updates mess with config files or overwrite them. Also heads up - you’re using @bot.event for greet() and farewell() when those should probably be @bot.command(). Won’t fix the login issue, but they won’t work once you’re connected either.