我使用 discord.py 在 python 中编写了一个 Discord 经济机器人。我使用 command_prefix = 'kash ' 将命令前缀设置为 'kash '。但是当我使用我之前定义和编码的命令之一时,它返回一个回溯,说该命令未定义。我试过更改前缀和命令名称,但它不起作用。这是完整的回溯:
Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "stock" is not found
这是股票功能之前的代码:
import discord
from discord.ext import commands
import json
import yfinance as yf
client = commands.Bot(command_prefix = 'kash ')
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.command
async def stock():
await message.channel.send('Please type: \n`$stock list` for list of stocks \n`$stock price` for a price of a specific stock \n`$buy` to buy a stock \n`$sell` to sell a stock')
有人可以帮忙吗?谢谢!
答案 0 :(得分:0)
因为你必须调用 client.command
@client.command()
async def stock(ctx):
await ctx.send('Please type: \n`$stock list` for list of stocks \n`$stock price` for a price of a specific stock \n`$buy` to buy a stock \n`$sell` to sell a stock')
PS:命令总是以 ctx
作为第一个参数,它是 Context