Discord.py 与python不一致的日期和时间错误 @client.event 消息上的异步定义(消息): 如果message.content.upper().startswith(“!now”) userID=message.author.id 等待客户端发送消息(message.channel“”(time.asctime()%'(userID)”)
我发现语法错误Discord.py 与python不一致的日期和时间错误 @client.event 消息上的异步定义(消息): 如果message.content.upper().startswith(“!now”) userID=message.author.id 等待客户端发送消息(message.channel“”(time.asctime()%'(userID)”),discord.py,Discord.py,我发现语法错误 尝试在其他类型时为discord bot发出命令!现在它将响应其日期和时间。upper表示“!now”需要大写为“!now”我不确定您是否正确复制了代码,但似乎缺少: 函数名称中的下划线(def on_message(message):) if语句末尾的冒号和右缩进 下面(if message.content.upper().startswith(“!now”):) 正如Mehvix指出的,您还将已转换为大写的字符串与小写字符串进行比较(如果message.content.s
尝试在其他类型时为discord bot发出命令!现在它将响应其日期和时间。upper表示“!now”需要大写为“!now”我不确定您是否正确复制了代码,但似乎缺少:
- 函数名称中的下划线(
)def on_message(message):
语句末尾的冒号和右缩进 下面(if
)if message.content.upper().startswith(“!now”):
)
我还建议使用python较新的格式特性,将wait行更改为类似以下内容的wait client.send_message(message.channel,f'{time.asctime()}->{message.author.id}')
这是最终的结果
@client.event
async def on message(message):
if message.content.upper().startswith('!now')
userID = message.author.id
await client.send_message(message.channel, '<@&s>' (time.asctime() % '(userID)')
谢谢你解决了这个问题,但我仍然面临着很多错误完美的我让它运行没有错误,但现在当我键入!现在不和谐没有发生
@client.event
async def on_message(message):
if message.content.startswith('!now'):
await client.send_message(message.channel, f'{time.asctime()} -> {message.author.id}')