我正在使用 discord.py 重写,在我的 help.py 文件夹中,当我将鼠标悬停在帮助命令上时,它显示 "help" is not accessedPylance (function) help: (ctx) -> None
我正在使用 vscode
如果您需要,这是我的帮助命令代码
import discord
from discord.ext import commands
class help(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(aliases=["commands"])
async def help(ctx,):
embed = discord.Embed(title = "What TimmyBot can do", description = "All the Commands TimmyBot can do so far", color = discord.Colour.light_grey())
embed.add_field(name = "````~Fun~````", value="**mindfuck** - A wholesome mindfuck :open_mouth: \n **deez** - Got em :peanuts: \n **fact** - Shows you a fact you may know or may not :nerd: \n **kill** - kills a user :dizzy_face: \n **avatar** - shows the avatar of the person you chose",inline=False)
embed.add_field(name="```~Utilities~```", value="**stats** - shows timmybot's latency and version :bar_chart: \n **user** - shows the information of the user that u @mentioned :detective:", inline=False)
embed.add_field(name="```~Moderation~```", value="**kick** - kicks a player :wave: \n **ban** - bans a player :exclamation: \n **unban** - unbans a player :white_check_mark: \n **clear** - clears messages (default 1) :dizzy_face:", inline = False)
embed.set_footer(text="Developed by YaBoiPerry#0326", icon_url='https://lh3.googleusercontent.com/LO8P_gAGXzJmS-vKWN1XAnzjg7oHOeI26yHI7BtFAL8oSzI-T5EMVH6_TC39FoxHe-LoIA=s120')
await ctx.send(embed=embed)
def setup(bot):
bot.add_cog(help(bot))
答案 0 :(得分:0)
你的代码看起来不错,除了一件事
help 已经是内置的
>>> type(help)
<class '_sitebuiltins._Helper'>
所以当你对一个类和一个内置函数使用相同的名字时,python 会感到困惑
重命名代码中的“帮助”应该可以修复它
答案 1 :(得分:0)
在 discord.py 中,bot 上已经存在一个内置的 help
命令,因此您可以通过在主文件中执行它来删除它。
在 Main.py 中,输入:
client.remove_command("help")
这样会删除默认的帮助命令。
最后,您没有将 self
放在括号中。你只是把 (ctx, ) 放在那里。在 cog 中,每个命令都必须将 self
放在括号中。
这是更新的代码:
@commands.command(aliases=["commands"])
async def help(self, ctx): # added self on the parenthesis
embed = discord.Embed(title = "What TimmyBot can do", description = "All the Commands TimmyBot can do so far", color = discord.Colour.light_grey())
embed.add_field(name = "````~Fun~````", value="**mindfuck** - A wholesome mindfuck :open_mouth: \n **deez** - Got em :peanuts: \n **fact** - Shows you a fact you may know or may not :nerd: \n **kill** - kills a user :dizzy_face: \n **avatar** - shows the avatar of the person you chose",inline=False)
embed.add_field(name="```~Utilities~```", value="**stats** - shows timmybot's latency and version :bar_chart: \n **user** - shows the information of the user that u @mentioned :detective:", inline=False)
embed.add_field(name="```~Moderation~```", value="**kick** - kicks a player :wave: \n **ban** - bans a player :exclamation: \n **unban** - unbans a player :white_check_mark: \n **clear** - clears messages (default 1) :dizzy_face:", inline = False)
embed.set_footer(text="Developed by YaBoiPerry#0326", icon_url='https://lh3.googleusercontent.com/LO8P_gAGXzJmS-vKWN1XAnzjg7oHOeI26yHI7BtFAL8oSzI-T5EMVH6_TC39FoxHe-LoIA=s120')
await ctx.send(embed=embed)
稍后感谢我 :D