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

Python开发Discord货币机器人出现SyntaxError报错如何解决?

报错原因

你代码中的c!是字符串类型的命令前缀参数,没有用单引号或双引号包裹,Python无法识别该语法,直接抛出SyntaxError。

修复方案

将c!用英文引号包裹即可,修正后的代码如下:

client = commands.Bot(command_prefix = 'c!')

如果你使用的是discord.py 2.0及以上版本,初始化Bot实例时还需要额外传入intents参数配置权限,否则消息命令无法正常触发,完整示例代码如下:

import discord
from discord.ext import commands

# 配置权限
intents = discord.Intents.default()
intents.message_content = True # 开启消息内容读取权限,必须在Discord开发者后台也开启对应权限

# 初始化Bot
client = commands.Bot(command_prefix = 'c!', intents=intents)

内容的提问来源于stack exchange,提问作者squishy

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 01:57:00