【发布时间】:2021-09-05 08:55:28
【问题描述】:
我需要有关此代码的帮助,因为我遇到了一个错误并且我不知道如何修复它。我是编码新手,我想在弄清楚这个问题后学习如何编码。我目前正在https://replit.com 上运行代码,如果您能弄清楚那将是很棒的,我会不断收到此错误!
代码:
import discord
import os
import colorama
from colorama import Fore, Style
import requests
import time
from colorama import Fore
from dotenv import load_dotenv
load_dotenv()
token = os.getenv('DISCORD_TOKEN')
def Cls():
os.system('cls')
Cls()
b = Style.BRIGHT
message = input("What do you want to say in the embed? ")
Cls()
token = "token""
Cls()
b = Style.BRIGHT
print(f"""
{b+Fore.GREEN}
██ ██ ███████ ███ ███ █████ ███████ ███████ ██████ ███ ███
██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██
████ ████
██ ██ █████ ██ ████ ██ ███████ ███████ ███████ ██ ██ ██ ████ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██
███████ ██ ███████ ██ ██ ██ ██ ███████ ███████ ██████ ██ ██
{b+Fore.BLUE} > {Fore.RESET}MASS DM
{b+Fore.BLUE} > {Fore.RESET}Creator: watch#0001
""")
watch = discord.Client()
@watch.event
async def on_connect():
for user in watch.user.friends:
try:
watchy = discord.Embed(color= discord.Color(0x2f3136))
watchy.set_author(name="join discord.gg/HeKbnh57 ")
watchy.add_field(name="discord.gg/HeKbnh57",value=message)
watchy.set_image(url="https://cdn.discordapp.com/attachments/811724526915289109/830113315405561896/image0.jpg")
time.sleep(.1)
await user.send(embed=watchy)
await user.send("https://www.youtube.com/watch?v=ixyIfsFZGg4")
time.sleep(.1)
print(f'messaged:' + Fore.GREEN + f' {user.name}')
except:
print(f"couldnt message: {user.name}")
print(f"Directed messaged all users friends")
watch.run(token, bot=False)
错误:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 300,
in static_login
data = await self.request(Route('GET', '/users/@me'))
File "/opt/virtualenvs/python3/lib/python3.8/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 "main.py", line 61, in <module>
watch.run(token, bot=False)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line
723, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line
702, in runner
await self.start(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line
665,
in start
await self.login(*args, bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line
511,
in login
await self.http.static_login(token.strip(), bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/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.
【问题讨论】:
-
这个错误是不言自明的:
discord.errors.LoginFailure: Improper token has been passed. -
我假设
token = "token"是一个例子,而实际的token是一个有效的,因为我认为"token"是完全无效的。您如何获得实际的token值?
标签: python discord discord.py