每次我 运行 我的 discord 机器人都会出错,我收到这个错误
i'm having an error with my discord bot each time i run it i get this error
Traceback (most recent call last):
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 254, 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 "e:\all in one bot\cafe-musain-bot\bot.py", line 79, in <module>
client.run('OTU1NjAyMjY1NzEwOTQ0Mjc2.YjkD9g.n0Qqhng0EA63JOcxwzajjm--wi0')
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 665, in start
await self.login(*args, bot=bot)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 304, 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 0x0000022765565550>
Traceback (most recent call last):
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
self._check_closed()
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
代码如下:
import asyncio
import discord
from discord.ext import commands
import random
token = 'Token'
intents=discord.Intents.all()
client = commands.Bot(command_prefix='?')
@client.event
async def on_ready():
print("bot is ready")
the rest...
client.run(token)
我尝试多次重置令牌并检查令牌是一个字符串没有发生相同的错误,尝试制作一个新的不和谐应用程序猜测问题出在我已经使用的那个中得到了相同的错误discord.py公会没有人知道如何修复它。
没有代码,很难给出准确的答案,但这听起来像是您的机器人令牌不正确。
提示您的令牌的错误行是 incorrect/improper:
raise LoginFailure('Improper token has been passed.') from exc
如何保证bot正确启动:
token = ''
bot.run(token) # client.run(token)
您可以找到您的令牌here。您需要确保令牌正确 - 否则,身份验证将不会成功。
这是改进后的代码。首先确保在您的主目录中创建一个包含以下内容的 config.py
文件:
TOKEN="Your Token"
这里是 main.py
代码:
import asyncio
import discord
from discord.ext import commands
import random
from config import TOKEN
client = commands.Bot(command_prefix='?', intents=intents)
@client.event
async def on_ready():
print("bot is ready")
'''
The rest Goes Code Here
'''
client.run(TOKEN)
Traceback (most recent call last):
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 254, 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 "e:\all in one bot\cafe-musain-bot\bot.py", line 79, in <module>
client.run('OTU1NjAyMjY1NzEwOTQ0Mjc2.YjkD9g.n0Qqhng0EA63JOcxwzajjm--wi0')
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 665, in start
await self.login(*args, bot=bot)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 304, 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 0x0000022765565550>
Traceback (most recent call last):
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
self._check_closed()
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
代码如下:
import asyncio
import discord
from discord.ext import commands
import random
token = 'Token'
intents=discord.Intents.all()
client = commands.Bot(command_prefix='?')
@client.event
async def on_ready():
print("bot is ready")
the rest...
client.run(token)
我尝试多次重置令牌并检查令牌是一个字符串没有发生相同的错误,尝试制作一个新的不和谐应用程序猜测问题出在我已经使用的那个中得到了相同的错误discord.py公会没有人知道如何修复它。
没有代码,很难给出准确的答案,但这听起来像是您的机器人令牌不正确。
提示您的令牌的错误行是 incorrect/improper:
raise LoginFailure('Improper token has been passed.') from exc
如何保证bot正确启动:
token = ''
bot.run(token) # client.run(token)
您可以找到您的令牌here。您需要确保令牌正确 - 否则,身份验证将不会成功。
这是改进后的代码。首先确保在您的主目录中创建一个包含以下内容的 config.py
文件:
TOKEN="Your Token"
这里是 main.py
代码:
import asyncio
import discord
from discord.ext import commands
import random
from config import TOKEN
client = commands.Bot(command_prefix='?', intents=intents)
@client.event
async def on_ready():
print("bot is ready")
'''
The rest Goes Code Here
'''
client.run(TOKEN)