Python开发Discord Bot报错TypeError:Client.run()缺少必填参数
修复Discord Bot启动时的Token参数错误
你遇到的TypeError: Client.run() missing 1 required positional argument: 'token'错误,是因为调用client.run()时没有传入必填的Bot令牌参数——你把{TOKEN}单独写在了一行,没有作为参数传递给run方法。
修复后的代码:
import discord from discord.ui import button, view from discord.ext import commands TOKEN = 'My token was here' intents = discord.Intents.default() intents.message_content = True client = discord.Client(intents=intents) @client.event async def on_ready(): print('Autenticazione riuscita. {0.user} is online!'.format(client)) # 将TOKEN作为参数传入run方法 client.run(TOKEN)
注意事项:
- 确保
TOKEN变量中的内容是你从Discord开发者平台获取的有效Bot令牌,不要泄露你的令牌。
内容的提问来源于stack exchange,提问作者makkich
相关产品推荐
相关产品推荐

