You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 20:35:16