如何转换为 discord.py 中的命令
How can I convert to a command in discord.py
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
假设您已经正确设置了 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)
发送到调用该命令的频道。
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
假设您已经正确设置了 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)
发送到调用该命令的频道。