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!