Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improper token passed

I'm following a basic tutorial for a Python Discord bot on YouTube and my code is underneath. It says:

discord.errors.LoginFailure: Improper token has been passed.

Before anyone asks, yes I have put in the bot token, not the id or secret.

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time

Client = discord.Client()
client = commands.Bot(command_prefix = "!")

@client.event
async def on_ready():
    print("Bot is ready!")

@client.event
async def on_message(message):
    if message.content == "cookie":
        await client.send_message(message.channel, ":cookie:")

client.run("token is here")
like image 814
slowpoking9 Avatar asked Jul 30 '18 21:07

slowpoking9


People also ask

Why is my discord BOT token not working?

TL;DR. If you are not seeing the Copy button located in your bot settings to copy your bot's token, this means the token has already been viewed once and is now hidden. You will need to regenerate the token using the Reset Token button and paste that new token into your code.


2 Answers

For me, my bot.py file looks like this:

import os
import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

client.run(TOKEN)

and since I used env (environment) modules, I created a new file with an empty name and with the .env extension in the same path in a folder. The env file only has this line of code:

DISCORD_TOKEN=DFHKJAhka7fdsKHJASDFk1jhaf5afd.HASDFafd23FHdfa_adfahHJKADF32W

So the problem for me was I was using brackets around the token code and after I removed it, it worked!

My code when it had brackets:

DISCORD_TOKEN={DFHKJAhka7fdsKHJASDFk1jhaf5afd.HASDFafd23FHdfa_adfahHJKADF32W}
like image 78
Armin Avatar answered Nov 07 '22 22:11

Armin


Make sure you grab the "Token" from the "Bot" page in the Discord development site, rather than the "Secret" from the "General Information" page.

I was having the same problem. My issue was solved by using the correct token from the Discord app page. I was using the "Secret" from the 'General Information' page (which generated the error in the original post for me) instead of the "Token" from the "Bot" page.

As sheneb said in the comment to this, this answer (probably) won't help the OP (since the question now says "Before anyone asks, yes I have put in the bot token, not the id or secret"). However, I found this question/page when searching for the answer, and my issue was solved with this information.

like image 36
Elyrith Avatar answered Nov 07 '22 21:11

Elyrith