我正在关注 YouTube 上 Python Discord 机器人的基本教程,我的代码在下面。它说:
discord.errors.LoginFailure:传递了不正确的令牌。
在有人问之前,是的,我已经输入了机器人令牌,而不是 ID 或秘密。
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")
原文由 slowpoking9 发布,翻译遵循 CC BY-SA 4.0 许可协议
对我来说,我的
bot.py
文件如下所示:因为我使用了 env(环境)模块,所以我在文件夹的同一路径中创建了一个空名称和 .env 扩展名的新文件。 env文件只有这行代码:
所以对我来说问题是我在令牌代码周围使用了括号,在我删除它之后,它起作用了!
我的代码有括号时: