【问题标题】:How can I convert to a command in discord.py如何转换为 discord.py 中的命令
【发布时间】:2021-07-08 09:47:57
【问题描述】:
def get_last_trade_price(TICKER):
    Asset = json.dumps(getQuotes(TICKER))
    raw = (json.loads(json.dumps(getQuotes(TICKER)))[0]["LastTradePrice"])
    raw = re.sub(",", "", raw)
    return float(raw)

如何将其转换为 discord.py 命令,如前缀,然后 FRA 用于交易价格等

【问题讨论】:

    标签: command discord.py


    【解决方案1】:

    假设您已经正确设置了 discord.ext.commands.Bot 实例,您可以使用这个:

    @commands.command(name="last_trading_price")
    async def get_last_trading_prive(ctx, ticker):
        raw = (json.loads(json.dumps(getQuotes(ticker)))[0]["LastTradePrice"])
        raw = re.sub(",", "", raw)
        await ctx.send(float(raw))
    

    为了举例,假设命令前缀是“!”。

    如果您要使用命令!last_trading_price AAPL,这会将float(raw) 发送到调用该命令的通道。

    【讨论】:

      猜你喜欢
      • 2021-02-09
      • 2021-07-11
      • 2021-03-26
      • 2021-06-02
      • 2018-04-02
      • 1970-01-01
      • 2021-10-08
      • 2020-02-10
      • 1970-01-01
      相关资源
      最近更新 更多