[英]Discord bot defined command not found
I coded a Discord economy bot in python using discord.py.我使用 discord.py 在 python 中编写了 Discord 经济型机器人。 I set the command prefix as 'kash ' using command_prefix = 'kash '.
我使用 command_prefix = 'kash' 将命令前缀设置为'kash'。 But when I use one of the commands that I defined AND coded earlier, it returned with a traceback saying that the command is not defined.
但是当我使用我之前定义和编码的命令之一时,它返回一个回溯,说明该命令未定义。 I've tried changing the prefix and command names, but it doesn't work.
我试过更改前缀和命令名称,但它不起作用。 Here is the complete traceback:
这是完整的回溯:
Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "stock" is not found
Here is the code until the stock function:这是库存 function 之前的代码:
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')
Can anyone help?任何人都可以帮忙吗? Thanks!
谢谢!
Because you have to call client.command
因为你必须调用
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: Commands always take ctx
as the first argument, it's the Context
PS:命令总是以
ctx
作为第一个参数,它是Context
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.