Python 未找到Discord bot定义的命令
我使用Discord.py在python中编写了一个Discord经济机器人。我使用command_prefix='kash'将命令前缀设置为'kash'。但是当我使用我之前定义和编码的一个命令时,它返回一个回溯,表示该命令没有定义。我尝试过更改前缀和命令名,但没有效果。以下是完整的回溯:Python 未找到Discord bot定义的命令,python,discord.py,Python,Discord.py,我使用Discord.py在python中编写了一个Discord经济机器人。我使用command_prefix='kash'将命令前缀设置为'kash'。但是当我使用我之前定义和编码的一个命令时,它返回一个回溯,表示该命令没有定义。我尝试过更改前缀和命令名,但没有效果。以下是完整的回溯: Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "stock&quo
Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "stock" is not found
以下是stock函数之前的代码:
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
@client.command()
异步def库存(ctx):
等待ctx.send('请键入:\n`$stock list`查看股票列表\n`$stock price`查看特定股票的价格\n`$buy`购买股票\n`$sell`出售股票')
PS:Commands总是将
ctx
作为第一个参数,它必须是@client.command()
。大多数情况下,它还需要像ctx
这样的参数,因此它将是async def stock(ctx)
,然后您可以使用ctx.send(“YourMessage”)