我目前正在尝试制作一个不和谐机器人。我正在尝试设置它,以便它在控制台中发送一条消息,该消息是(用户)在(通道)中发送的(命令)。按照ctx的工作方式,字符串总是有一个前导和尾随空格。我想知道如何删除所述空白。我试过使用.strip,如你所见,但它根本不起作用
def receivedcommand(ctx):
print(current_datetime,'INFO: Chat Command Received;',ctx.author.name,'sent \"',ctx.message.content.strip(),'\" in \"#',ctx.channel.name.strip()[2:],'\"')
[2:]
用于删除我的服务器中的前缀,在本例中是一个表情符号和一个不协调兼容管道
该函数返回
[07/16/21 21:03:39] INFO: Chat Command Received; Vyladence sent " |parrot awa2 " in "# programming "
在#编程中接收Vyladence发送的|parrot
命令时。有人知道我搞砸了什么吗
你确实剥夺了所有可以剥夺的空间
print
本身正在"
和ctx.message.content.strip()
的值之间添加空格不要将多个参数传递给^ {},考虑建立一个字符串:
实际上,您已将其剥离,因为您使用的是逗号,它会自动添加一个空格分隔符,若要修复它,请尝试以下操作:
例如:
使用逗号打印会自动添加空格分隔符,如下所示:
添加
sep=''
(将分隔符分配给空字符串)可以:相关问题 更多 >
编程相关推荐