Python 使用Discord.py检查消息长度

Python 使用Discord.py检查消息长度,python,discord.py,Python,Discord.py,我正试图使它,使机器人答复的东西时,消息长度超过120个字符 这是到目前为止我的代码 @client.event async def on_message(message): if message.author == client.user: return if #here I'm trying to make the thing I just described 您可以通过len(message.clean\u content)获取消息长度: @client

我正试图使它,使机器人答复的东西时,消息长度超过120个字符 这是到目前为止我的代码

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if #here I'm trying to make the thing I just described

您可以通过
len(message.clean\u content)
获取消息长度:

@client.event
异步def on_消息(消息):
如果message.author==client.user:
返回
如果len(消息清洁内容)>20:
#在这里做事
这里使用干净的内容,因为它返回客户端显示的消息内容,例如
将转换为
#name
。如果要按discord计算消息长度,请使用
message.content


参考文献:

根据,您应该能够使用
message.content
str
的形式获取消息的内容。那么,这只是一个比较的问题:

if len(message.content) > 120:
    #reply to message here

如上所述,您也可以使用
message.clean_content

有什么问题?您知道如何检查字符串的长度吗<代码>消息。清除内容将返回字符串。尝试使用这两条信息。