【发布时间】:2021-01-23 22:26:56
【问题描述】:
我已成功在 cog(帮助命令)中加载了 1 个命令,但无法加载其余命令以及所有其他 cogs
源代码;
- 加载齿轮的代码
@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 命令有效。
谢谢
【问题讨论】:
标签: python python-3.x discord discord.py discord.py-rewrite