I coded a Discord economy bot in python using discord.py. I set the command prefix as 'kash ' using command_prefix = '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:
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()
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.