Also ich versuche gerade einen simplen Discord Bot mit der Discord API zu schreiben und versuche mich gerade erstmal mit dem Bot(das Script) in den Bot User Account einzuloggen. Leider erhalte ich hier einen 401 HTTP Error...Ich dachte erst es liegt an dem Authentifizierungs_Token, aber das ist nicht der Fall da ich mir den Token habe ausgeben lassen und er ist identisch. Woran könnte der Error sonst noch liegen?
Hier ist mein Code:
Hier ist mein Code:
Python:
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 !')
print(TOKEN)
client.run(TOKEN)
Code:
#.env
DISCORD_TOKEN = {hier-wäre-der-Token}
DISCORD_GUILD = {your-guild-name}
Code:
python3 .\bot.py
{hier-wäre-der-token}
Traceback (most recent call last):
File "C:\Users\4TL4S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\http.py", line 288, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "C:\Users\4TL4S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\http.py", line 245, 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 ".\bot.py", line 15, in <module>
client.run(TOKEN)
File "C:\Users\4TL4S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 678, in run
return future.result()
File "C:\Users\4TL4S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 658, in runner
await self.start(*args, **kwargs)
File "C:\Users\4TL4S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 621, in start
await self.login(*args, bot=bot)
File "C:\Users\4TL4S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 472, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Users\4TL4S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\http.py", line 292, in static_login
raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001EBD94FB700>
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 719, in call_soon
self._check_closed()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 508, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed