discord.ext.commands.errors.MissingRequiredArgument:bot 是缺少的必需参数

时间:2021-06-28 20:33:05

标签: python discord.py

ma​​in.py

[BadImageFormatException: Could not load file or assembly 'Microsoft.SqlServer.DTSRuntimeWrap' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +225
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +110
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
   System.Reflection.Assembly.Load(String assemblyString) +34
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.SqlServer.DTSRuntimeWrap' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +767
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +256
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +58
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +281
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +69
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +137
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +848

[HttpException (0x80004005): Could not load file or assembly 'Microsoft.SqlServer.DTSRuntimeWrap' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +532
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +111
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +714

ping.py

import os
import discord
from discord.ext import commands, tasks

bot = commands.Bot(command_prefix=commands.when_mentioned_or('moon '),
                   case_insensitive=True)

my_secret = os.environ['token']
for file in os.listdir("./cogs"):
    if file.endswith(".py"):
        name = file[:-3]
        bot.load_extension(f"cogs.{name}")

for utility in os.listdir("./cogs/utility"):
    if utility.endswith(".py"):
        name = utility[:-3]
        bot.load_extension(f"cogs.utility.{name}")


@bot.event
async def on_ready():
    print('?  {} está online!'.format(bot.user.name))


bot.run(my_secret)

当我使用 ping 命令时,出现此错误:

import discord
from discord.ext import commands

class Utility(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def ping(self, ctx, bot):
        await ctx.send('A Lua está com {}ms'.format(bot.latency * 100))

def setup(bot):
    bot.add_cog(Utility(bot))

1 个答案:

答案 0 :(得分:0)

您在 ping.py 中有 3 个错误:

  1. ping 命令中不需要参数。
  2. 应该是 (self.bot.latency) 而不是 (bot.latency)
  3. 要将 ping 命令中的秒转换为微秒,请将 (self.bot.latency * 100) 替换为 (self.bot.latency * 1000)

这个 ping.py 程序应该可以工作:

import discord
from discord.ext import commands

class Utility(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def ping(self, ctx):
        await ctx.send('A Lua está com {}ms'.format(self.bot.latency * 1000))

def setup(bot):
    bot.add_cog(Utility(bot))