python-3.x PyCord Discord Bot两个参数

omqzjyyz  于 2023-05-02  发布在  Python
关注(0)|答案(1)|浏览(195)

我试图有一个斜杠命令,至少需要两个参数,由于某种原因,它是不工作,我找不到任何文件。

@bot.slash_command(name='greet', description='Greet someone!')
@discord.option(
    "name",
    description="Enter Name in format: John Doe",
    required=False,
    default='John Doe'
)
@discord.option(
    "collar",
    description="Enter Collar number e.g. 1789",
    required=False,
    default='1123'
)
async def greet(
    ctx: discord.ApplicationContext,
    name: str,
    collar: str
):
    await ctx.send(f'{name} {collar} \n' "http://imgur.com/gallery/YiMUiop")

bot.run(os.getenv('TOKEN')) # run the bot with the token
f5emj3cl

f5emj3cl1#

这就是我在PyCord v2中使用的。3

from discord import Option

@bot.slash_command(description = "Greet someone!")
async def greet(ctx, 
               name:Option(str,
                           description="Enter Name in format: John Doe",
                           required=False,
                           default='John Doe'),
               collar: Option(str,
                              description="Enter Collar number e.g. 1789",
                              required=False,
                              default='1123'
                             )
              ):
  await ctx.respond(f'{name} {collar} \n' "http://imgur.com/gallery/YiMUiop")

bot.run(os.getenv('TOKEN')) # run the bot with the token

相关问题