簡體   English   中英

Discord 未找到機器人定義的命令

[英]Discord bot defined command not found

我使用 discord.py 在 python 中編寫了 Discord 經濟型機器人。 我使用 command_prefix = 'kash' 將命令前綴設置為'kash'。 但是當我使用我之前定義和編碼的命令之一時,它返回一個回溯,說明該命令未定義。 我試過更改前綴和命令名稱,但它不起作用。 這是完整的回溯:

Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "stock" is not found

這是庫存 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')

任何人都可以幫忙嗎? 謝謝!

因為你必須調用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM