社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

我制作了一个python机器人,可以获取股票的价格,但我如何制作它,使参数不使用空格?

chicken duck • 3 年前 • 1535 次点击  
@client.command()
async def stockprice(ctx, stock):
    await ctx.send(stock + ' price: ' + getStockPrice(stock))

我制作了一个python机器人,可以获取股票的价格,但我如何制作它,使论点不使用#空格?

例子:

!stockprice bitcoin => !stockprice.bitcoin
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/133800
 
1535 次点击  
文章 [ 1 ]  |  最新文章 3 年前
furas
Reply   •   1 楼
furas    4 年前

我不知道我是否理解你的问题。


如果要删除字符串两侧的空格/制表符/回车符,则只需

stock = stock.strip() 

如果您想使用命令作为带有点的单个字符串 !stockprice.bitcoin -那你就得用 on_message(message) 将其转换为 !stockprice bitcoin 使用 process_commands() 寄到 @client.command()

差不多是这样的

@client.event
def on_message(msg):

    if msg.author.bot:
        return

    if msg.content.startswith('!stockprice.'):
       msg.content = msg.content.replace('!stockprice.', '!stockprice ')
    
    await process_commands(msg)