【问题标题】:How do I use the args and Question argument at once如何同时使用 args 和 Question 参数
【发布时间】:2021-05-06 21:08:08
【问题描述】:

我试图让我的机器人将某人键入的任何内容粘贴到消息中,并且当他们不键入任何内容时不允许他们使用该命令,因此使用 &test random text 它将显示 random text,如果我执行&test 会显示错误消息you have to type something in 或类似的内容,

import discord
import os
from discord.ext import commands
from keep_alive import keep_alive
import random
from discord import Member, Embed
from discord.ext.commands import BucketType, cooldown
from discord.ext.commands import errors
import asyncio


@client.command()
@cooldown(4, 11, BucketType.user)
async def test(ctx, args, *, question):
   response = ""
   for arg in args:
      response = response + " " + arg
 
   embed=discord.Embed(title="\"" + response + "\"", colour=ctx.author.colour)
   embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
   somegifs = random.choice(gifs)
   embed.set_image(url=somegifs)
   embed.set_footer(text="Test embed")
   await ctx.send(embed=embed)
@test.error
async def test_error(ctx, error):
    if isinstance(error, errors.MissingRequiredArgument):
        embed2 = discord.Embed(title="you have to type something in", colour=ctx.author.colour)
        embed2.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
        embed2.set_footer(text="Test embed")
        await ctx.send(embed=embed2)
    else: raise(error)

这就是我正在使用的,每次我使用命令时,不管是不是文本,它都会显示错误消息, 编辑:再次测试该命令后,它会响应,但只有当您输入多个单词并且它只显示第一个单词,字母之间有空格as shown here

【问题讨论】:

  • 什么问题,有什么错误吗?
  • 单独使用命令时显示错误消息,仅使用一个单词的命令时,如果使用多个单词,则仅显示第一个单词

标签: python python-3.x discord discord.py


【解决方案1】:

您可以像这样格式化命令:

@bot.command()
async def test(ctx, *, args):
    await ctx.send(args)

然后是您的错误处理以及之后的所有内容

【讨论】:

  • 没错,您不需要额外的步骤,谢谢。我会编辑它
猜你喜欢
  • 2018-07-16
  • 1970-01-01
  • 2021-12-13
  • 1970-01-01
  • 2014-06-05
  • 2018-10-21
  • 2020-11-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多