【发布时间】:2021-08-07 00:39:56
【问题描述】:
我使用 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')
有人可以帮忙吗?谢谢!
【问题讨论】:
-
必须是
@client.command()。大多数情况下,它还需要像ctx这样的参数,所以它会是async def stock(ctx),然后你可以使用ctx.send("YourMessage")
标签: python discord.py