@client.command() async def stockprice(ctx, stock): await ctx.send(stock + ' price: ' + getStockPrice(stock))
我制作了一个python机器人,可以获取股票的价格,但我如何制作它,使论点不使用#空格?
例子:
!stockprice bitcoin => !stockprice.bitcoin
我不知道我是否理解你的问题。
如果要删除字符串两侧的空格/制表符/回车符,则只需
stock = stock.strip()
如果您想使用命令作为带有点的单个字符串 !stockprice.bitcoin -那你就得用 on_message(message) 将其转换为 !stockprice bitcoin 使用 process_commands() 寄到 @client.command()
!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)