【问题标题】:Discord bot defined command not found未找到 Discord bot 定义的命令
【发布时间】: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


【解决方案1】:

因为你必须打电话给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

【讨论】:

    猜你喜欢
    • 2021-12-20
    • 2017-08-31
    • 2021-01-21
    • 2021-04-30
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 2020-02-11
    相关资源
    最近更新 更多