所以我实际上正在尝试制作一个机器人,它会向 discord 服务器发送嵌入消息,最初不会发送,我会执行命令,然后它会在服务器中发送嵌入消息。但是当我尝试运行机器人时,我不断收到错误消息。顺便说一句,我正在使用 Pycharm,无论如何看看。
import discord
from discord.ext import commands
import asyncio<p></p>
<pre><code>bot_prefix = "`"
bot = commands.Bot(command_prefix=bot_prefix)
@bot.event
async def on_event():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print("---------")
@bot.command(pass_context=True)
async def embed(ctx):
embed = discord.Embed(
title="Blog Post # 2",
url="https://darksiderclan2.weebly.com/uploads/1/1/4/7/114760003/published/battle.png?1510944203/n",
color=0xffff00,
description="Aquí hay una segunda publicación de blog para su sitio web/n",
)
await bot.say(embed=embed)
bot.run('TOKEN')
</code></pre>
<p></p>
那是我的代码,现在我得到的错误是:
`C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\python.exe "C:/Users/Default.Default-PC/Desktop/Chief Bot.py"
Traceback (most recent call last):
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\http.py", line 252, in static_login
data = yield from self.request(Route('GET', '/users/@me'))
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\http.py", line 212, in request
raise HTTPException(r, data)
discord.errors.HTTPException: UNAUTHORIZED (status code: 401): 401: Unauthorized<p></p>
<p>The above exception was the direct cause of the following exception:</p>
<p>Traceback (most recent call last):
File "C:/Users/Default.Default-PC/Desktop/Chief Bot.py", line 27, in
bot.run('WPUi5O1UAxfQiiK2GDz9cktDO82ApySM')
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py", line 567, in run
return task.result()
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\asyncio\futures.py", line 274, in result
raise self._exception
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py", line 487, in _silence_gathered
fut.result()
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\asyncio\futures.py", line 274, in result
raise self._exception
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\asyncio\tasks.py", line 239, in _step
result = coro.send(None)
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py", line 474, in start
yield from self.login(*args, bot=bot)
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py", line 352, in login
yield from self.http.static_login(token, bot=bot)
File "C:\Users\Default.Default-PC\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\http.py", line 256, in static_login
raise LoginFailure('Improper token has been passed.') from e
discord.errors.LoginFailure: Improper token has been passed.</p>
<p>Process finished with exit code 1`</p>
请告诉我问题是什么?我以前制作机器人时没有遇到过这个错误。
请您参考如下方法:
我知道这个线程很旧,但对于仍在寻找答案的任何人(因为它是您搜索时弹出的第一件事)
他可能使用了客户端 token 而不是机器人 token ,要获取机器人 token ,您必须转到 Discord Delevoper 门户并单击左侧的“Bot”选项卡,然后单击“单击以在机器人名称的输入部分下显示 token ”,复制并插入到您的代码中。为我工作。
