首页 > 解决方案 > 提高 MissingRequiredArgument(param) discord.ext.commands.errors.MissingRequiredArgument:cooldown 是缺少的必需参数

问题描述

我不断收到此错误:

忽略 on_command_error 中的异常

回溯(最近一次通话最后):

_run_event 中的文件“/usr/local/lib/python3.8/dist-packages/discord/client.py”,第 343 行
等待 coro(*args, **kwargs)

文件“bot.py”,第 191 行,on_command_error
引发错误

文件“/usr/local/lib/python3.8/dist-packages/discord/ext/commands/bot.py”,第 939 行,在调用
await ctx.command.invoke(ctx)

文件“/usr/local/lib/python3.8/dist-packages/discord/ext/commands/core.py”,第 855 行,在调用
await self.prepare(ctx)

文件“/usr/local/lib/python3.8/dist-packages/discord/ext/commands/core.py”,第 789 行,准备
等待 self._parse_arguments(ctx)

_parse_arguments 中的文件“/usr/local/lib/python3.8/dist-packages/discord/ext/commands/core.py”,第 697 行,
transform = await self.transform(ctx, param)

文件“/usr/local/lib/python3.8/dist-packages/discord/ext/commands/core.py”,第 542 行,在 transform
raise MissingRequiredArgument(param) discord.ext.commands.errors.MissingRequiredArgument:冷却时间是缺少的必需参数。

请帮我说这是我的代码

import discord
import json
import requests
import time
from discord.ext import commands
from discord.ext.commands import cooldown
from datetime import datetime, timedelta

on_cooldown = {}
client = commands.Bot(command_prefix = "!")
client.remove_command("help")
async def get_user_data():
  with open("account.json","r") as f:
    users = json.load(f)
  return users

@client.event
async def on_ready():
  print("Bot is ready")
  print('Connected to bot: {}'.format(client.user.name))
  print('Bot ID: {}'.format(client.user.id))
  await client.change_presence(activity=discord.Game(name="Dwayne is protecting"  + str(len(client.guilds)) + "Eggplants ", type=0))

#help command
@client.command(pass_context=True, aliases=['Help'])
async def help(ctx):
    embed=discord.Embed(title="Help", description='Bot prefix = ?', color=0x7a0000)
    embed.add_field(name="Spammers", value="!post <number> <message> <quantity>\n!plan", inline=True)
    embed.add_field(name="Admin", value="!createa <User ID> <ExpDate> <cooldown> (Y-M-D)\n!bana <User ID> <Reason+Reason>\n?purge <amount>\n!ban <user> <reason>\n!unban <user>", inline=False)
    embed.set_footer(text="Dwayne Bot")
    await ctx.send(embed=embed)

@client.command()
async def post(ctx, To, message, amount):
  users = await get_user_data()
  if str(ctx.author.id) in users:
    if users[str(ctx.author.id)]['Banned'] == 'N':
      timeleft = datetime.strptime(users[str(ctx.author.id)]['expDate'],'%Y-%m-%d') - datetime.now()
      if timeleft.days <= 0:
         em = discord.Embed(color=0x7a0000, description="Sorry your plan on this tool has expired")
         await ctx.send(embed=em)
      else:
        move_cooldown = users[str(ctx.author.id)]["cooldown"]
        try:
          last_move = datetime.now() - on_cooldown[ctx.author.id]
        except KeyError:
          last_move = None
          on_cooldown[ctx.author.id] = datetime.now()
        if last_move is None or last_move.seconds > move_cooldown:
          on_cooldown[ctx.author.id] = datetime.now()
          message = message.replace('+',' ')
          requests.get(f'http://45.61.54.145/api.php?key=CRzQHsKuHpF3x2M9GFrR&to={To}&message={message}&amount={amount}')
          await ctx.send('Check Messages')
          await ctx.message.delete()
          author = ctx.message.author
          test_e = discord.Embed(colour = discord.Colour.from_rgb(166, 245, 255))
          test_e.set_author(name="Hello thank you for using our spammer!")
          test_e.add_field(name="Request", value="Your request to spam this number has been successful!", inline=False)
          test_e.add_field(name="Refresh", value="You may use this command again in 5 minutes this is to keep our spammer less laggy!")
          await author.send(embed=test_e)
        else:
            embed = discord.Embed(color=0x7a0000, description="You're Cooldown Is Still Active!")
            await ctx.send(embed=embed)
    else:
      embed=discord.Embed(title=f"{ctx.author.name}", color=0x7a0000)
      embed.add_field(name="User Banned", value=f"Banned: Yes\nBannedOn: {users[str(ctx.author.id)]['BannedOn']}\nBannedBy: {users[str(ctx.author.id)]['BannedBy']}\nBannedReason: {users[str(ctx.author.id)]['BannedReason']}")
      embed.set_footer(text="madeby: toxic")
      await ctx.send(embed=embed)
  else:
    embed = discord.Embed(color=0x7a0000, description=f"Sorry you don't have a plan on this tool")
    await ctx.send(embed=embed)

标签: pythondiscorddiscord.py

解决方案


在 discord.py 中,rewrite(高于 v1.0+ 版本)pass_context已从命令中删除。 https://discordpy.readthedocs.io/en/stable/migrating.html#context-changes

尝试从帮助命令中删除它。


推荐阅读