在cog discord.py上仅加载了1条命令

时间:2020-10-08 20:06:07

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

我已经在齿轮中成功加载了1条命令(帮助命令),但其余所有齿轮都无法加载

源代码;

  • 加载齿轮的代码
@bot.command()
async def load(ctx, extension):
    id = str(ctx.author.id)
    if id == '(my discord id)':
        bot.load_extension(f'cogs.{extension}')
    else:
        await ctx.send("You can't do this!")

@bot.command()
async def unload(ctx, extension):
    id = str(ctx.author.id)
    if id == '(my discord id)':
        bot.unload_extension(f'cogs.{extension}')
    else:
        await ctx.send("You can't do this!")

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        bot.load_extension(f'cogs.{filename[:-3]}')
  • 嵌齿轮中的代码
import discord
from discord.ext import commands

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

    @commands.command()
    async def help(self, ctx):
        author = ctx.message.author

        embed = discord.Embed(
            colour = discord.Colour.green()
        )

        embed.set_author(name='Help')
        embed.add_field(name='dtog!about', value="Shows information about the bot.", inline=False)
        embed.add_field(name='dtog!invite', value="Get the bot invite link, so you can add it to your server.", inline=False)
        embed.add_field(name='dtog!support', value="Get an invite to the support server..", inline=False)
        embed.add_field(name='dtog!randomcountry', value="Post a random country, powered by PyCountry.", inline=False)
        embed.add_field(name='dtog!ping', value="Shows the bot's latency.", inline=False)
        embed.add_field(name='dtog!say', value="Say any message in the same channel as the command.", inline=False)
        embed.add_field(name='dtog!roll', value="Post a number from 1-100.", inline=False)
        embed.add_field(name='dtog!ship', value="Posts your chances of getting love.", inline=False)

        await ctx.send(embed=embed)

    @commands.command()
    async def support(self, ctx):
        author = ctx.message.author

        embed = discord.Embed(
            colour = discord.Colour.green()
        )

        embed.add_field(name='Support Server', value="Need support? Then join the community server at my server to report bugs and talk to the owner!", inline=False)

        await ctx.send(embed=embed)

    @commands.command()
    async def invite(self, ctx):
        author = ctx.message.author
    
        embed = discord.Embed(
            colour = discord.Colour.green()
        )
    
        embed.add_field(name='Bot Invite Link', value='[Bot Invite Link](https://discord.com/oauth2/authorize?client_id=761221166907916329&permissions=8&scope=bot)', inline=False)
    
        await ctx.send(embed=embed)

    @commands.command()
    async def about(self, ctx):
        author = ctx.message.author

        embed = discord.Embed(
            colour = discord.Colour.green()
        )

        embed.set_author(name='Information')
        embed.add_field(name='What is this?', value="The DTOG bot is a all-in-one bot hosted and coded by DTOG#0001 (ID 721029142602056328).", inline=False)
        embed.add_field(name='What does DTOG bot offer?', value="The bot houses a powerful plethora of fun and utility commands, and more features are planned to be added.", inline=False)
        embed.add_field(name='What language is the bot coded in?', value="Discord.py Rewrite.", inline=False)
        embed.add_field(name='How do I invite the bot to my server?', value="You can invite the bot [here.](my bot invite link")

        await ctx.send(embed=embed)

        author = ctx.message.author

        embed = discord.Embed(
            colour = discord.Colour.green()
        )

        embed.set_author(name='DTOG Bot To-Do-List')
        embed.add_field(name='Near Future', value="<:x:763456392362197042> Make the bot viable for logging.\n<:x:763456392362197042> Add a Editsnipe command.\n<:x:763456392362197042> Add a Snipe command.\n<:x:763456392362197042> Add a meme feature.\n<:x:763456392362197042> Go back to coding dtog!poll.\n<:x:763456392362197042> Add the bot to the cloud.", inline=False)
        embed.add_field(name='Far Future', value="<:x:763456392362197042> Add music functionality.", inline=False)

        await ctx.send(embed=embed)
        
def setup(bot):
    bot.add_cog(Help(bot))

还要注意,我已将“ os”导入到主要bot.py文件中,并且主要help命令正在工作。我不知道为什么只有help命令起作用。

谢谢

1 个答案:

答案 0 :(得分:0)

好的,我已经解决了这个问题。这是解决方法;

替换

curl -i http://localhost/

使用

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