Python Discord.py-ctx是必需的参数

2024-04-19 17:11:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图制造一个不和谐的机器人,我正在遵循一个简单的教程,任何我不能得到最简单的命令来工作。 我在Python3.6上运行discord.py版本0.16.12

    #Imports
import time
import discord
import asyncio
from discord.ext import commands

#Initialize
client = discord.Client()#Creates Client
bot = commands.Bot(command_prefix='!')#Sets prefix for commands(!Command)

#Code
@bot.command()
async def SendMessage(ctx):
    await ctx.send('Hello')

代码应该可以工作,但是它给了我一个错误discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.


Tags: pyimport命令版本clientprefixisbot
2条回答

默认情况下,Discord.py命令不会传递上下文。您指定希望通过将so作为参数传递给decorator来传递上下文。

@bot.command(pass_context=True)
async def SendMessage(ctx):
    await ctx.send('Hello')

documentation

A command must always have at least one parameter, ctx, which is the Context as the first one.

相关问题 更多 >