PyCharm不';t识别';配置';,Pycharm 2020.3.3 Python 3.9
我从GitHub中找到了这个帮助命令,并将其放在我的代码中。我检查了所有错误,在这些错误下是未定义PyCharm不';t识别';配置';,Pycharm 2020.3.3 Python 3.9,python,pycharm,python-3.9,Python,Pycharm,Python 3.9,我从GitHub中找到了这个帮助命令,并将其放在我的代码中。我检查了所有错误,在这些错误下是未定义config的错误。我怎么修理它 链接到GitHub: 代码(我知道代码很长): 导入不一致 从discord.ext导入命令 从discord开始。禁止导入错误 “”“此自定义帮助命令是用Discord.py编写的任何Discord Bot上默认帮助命令的完美替代品! 但是,必须将“bot.remove_command('help')”放在bot中,并且该命令必须位于cog中才能工作。 Jare
config
的错误。我怎么修理它
链接到GitHub:
代码(我知道代码很长):
导入不一致
从discord.ext导入命令
从discord开始。禁止导入错误
“”“此自定义帮助命令是用Discord.py编写的任何Discord Bot上默认帮助命令的完美替代品!
但是,必须将“bot.remove_command('help')”放在bot中,并且该命令必须位于cog中才能工作。
Jared Newsom(又名Jared M.F.)的原创概念
[已删除]https://gist.github.com/StudioMFTechnologies/ad41bfd32b2379ccffe90b0e34128b8b
由github.com/nonchris重写和优化
https://gist.github.com/nonchris/1c7060a14a9d94e7929aa2ef14c41bc2
您需要设置三个变量以使cog运行。
请看第51到56行
"""
异步def发送_嵌入(ctx,嵌入):
"""
处理嵌入发送的函数
->获取上下文并嵌入以发送
-尝试在通道中发送嵌入
-失败时尝试发送正常消息
-尝试发送缺少权限的嵌入私有信息
如果这一切都失败了:https://youtu.be/dQw4w9WgXcQ
"""
尝试:
等待ctx.send(嵌入=嵌入)
除禁止外:
尝试:
等待ctx.send(“嘿,似乎我无法发送嵌入。请检查我的权限:)”)
除禁止外:
等待ctx.author.send(
f“嘿,似乎我无法在{ctx.guild.name}上的{ctx.channel.name}中发送任何消息\n”
f“您可以通知服务器团队这个问题吗?:微微一笑:”,embed=embed)
类帮助(commands.Cog):
"""
发送此帮助消息
"""
def uuu init uuuu(自我,机器人):
self.bot=bot
@commands.command()
#@commands.bot\u拥有\u权限(add\u reactions=True,embed\u links=True)
异步def帮助(self、ctx、*输入):
“”“显示该机器人程序的所有模块”“”
# !设置这些变量以使COG正常工作!
prefix=#输入您的前缀-从配置加载,作为字符串或您想要的方式!
#设置所有者名称-如果您不想被提及,请删除第49-60行并调整帮助文本(第88行)
所有者=#输入您的DISCORD-ID
所有者名称=#输入您的用户名#1234
#检查是否给出了cog参数
#如果不是:发送与cog无关的所有模块和命令
如果没有输入:
#检查所有者是否在此服务器上-用于“标记”所有者
尝试:
owner=ctx.guild.get_成员(config.owner)。提及
除属性错误为e外:
owner=config.owner\u NAME
#开始构建嵌入
emb=discord.Embed(title='Commands and modules',color=discord.color.blue(),
description=f'Use`{prefix}help`获取有关该模块的更多信息'
f':笑脸:\n')
#迭代槽齿轮,收集描述
cogs_desc=“”
对于self.bot.cogs中的cog:
cogs_desc+=f'{cog}{self.bot.cogs[cog]。\uuu doc\uuu}\n'
#添加要嵌入的齿轮的“列表”
emb.add_字段(name='Modules',value=cogs_desc,inline=False)
#集成未分类命令
命令_desc=''
对于self.bot.walk_commands()中的命令:
#如果齿轮不在齿轮中
#如果cog名称为None且命令未隐藏,则列出命令
如果不是command.cog_名称,也不是command.hidden:
commands_desc+=f'{command.name}-{command.help}\n'
#添加那些要嵌入的命令
如果命令_desc:
emb.add_字段(name='不属于模块',value=commands_desc,inline=False)
#设置有关作者的信息
emb.add_字段(name=“About”,value=f)“机器人程序是由Chriѕ#0001基于discord.py开发的。\n\
此版本由{owner}维护\n\
请访问https://github.com/nonchris/discord-fury 提交想法或错误。”)
emb.set_footer(text=f“Bot正在运行{config.VERSION}”)
#给定一个cog名称时调用的块
#试图找到匹配的cog及其命令
elif len(输入)==1:
#迭代槽齿
对于self.bot.cogs中的cog:
#检查cog是否匹配
如果cog.lower()==输入[0]。lower():
#制作标题-从类下的文档字符串获取说明
emb=discord.Embed(title=f'{cog}-Commands',description=self.bot.cogs[cog]。\uuuuu doc\uuuu,
color=discord.color.green())
#从cog获取命令
对于self.bot.get_cog(cog.get_commands()中的命令:
#如果cog未隐藏
如果不是command.hidden:
emb.add_字段(name=f“`{config.PREFIX}{command.name}`”,value=command.help,inline=False)
#发现齿轮断裂环
打破
#如果没有找到输入
#是的,对于有else语句的循环,当没有发出“break”时调用它
其他:
emb=discord.Embed(title=“那是什么?!”,
description=f“我以前从未听到过名为`{input[0]}`的模块:尖叫:”,
color=discord.color.orange())
#请求的齿轮太多-一次只允许一个
elif len(输入)>1:
emb=discord.Embed(title=“太多了。”,
description=“请仅在
import discord
from discord.ext import commands
from discord.errors import Forbidden
"""This custom help command is a perfect replacement for the default one on any Discord Bot written in Discord.py!
However, you must put "bot.remove_command('help')" in your bot, and the command must be in a cog for it to work.
Original concept by Jared Newsom (AKA Jared M.F.)
[Deleted] https://gist.github.com/StudioMFTechnologies/ad41bfd32b2379ccffe90b0e34128b8b
Rewritten and optimized by github.com/nonchris
https://gist.github.com/nonchris/1c7060a14a9d94e7929aa2ef14c41bc2
You need to set three variables to make that cog run.
Have a look at line 51 to 56
"""
async def send_embed(ctx, embed):
"""
Function that handles the sending of embeds
-> Takes context and embed to send
- tries to send embed in channel
- tries to send normal message when that fails
- tries to send embed private with information abot missing permissions
If this all fails: https://youtu.be/dQw4w9WgXcQ
"""
try:
await ctx.send(embed=embed)
except Forbidden:
try:
await ctx.send("Hey, seems like I can't send embeds. Please check my permissions :)")
except Forbidden:
await ctx.author.send(
f"Hey, seems like I can't send any message in {ctx.channel.name} on {ctx.guild.name}\n"
f"May you inform the server team about this issue? :slight_smile: ", embed=embed)
class Help(commands.Cog):
"""
Sends this help message
"""
def __init__(self, bot):
self.bot = bot
@commands.command()
# @commands.bot_has_permissions(add_reactions=True,embed_links=True)
async def help(self, ctx, *input):
"""Shows all modules of that bot"""
# !SET THOSE VARIABLES TO MAKE THE COG FUNCTIONAL!
prefix = # ENTER YOUR PREFIX - loaded from config, as string or how ever you want!
# setting owner name - if you don't wanna be mentioned remove line 49-60 and adjust help text (line 88)
owner = # ENTER YOU DISCORD-ID
owner_name = # ENTER YOUR USERNAME#1234
# checks if cog parameter was given
# if not: sending all modules and commands not associated with a cog
if not input:
# checks if owner is on this server - used to 'tag' owner
try:
owner = ctx.guild.get_member(config.OWNER).mention
except AttributeError as e:
owner = config.OWNER_NAME
# starting to build embed
emb = discord.Embed(title='Commands and modules', color=discord.Color.blue(),
description=f'Use `{prefix}help <module>` to gain more information about that module '
f':smiley:\n')
# iterating trough cogs, gathering descriptions
cogs_desc = ''
for cog in self.bot.cogs:
cogs_desc += f'`{cog}` {self.bot.cogs[cog].__doc__}\n'
# adding 'list' of cogs to embed
emb.add_field(name='Modules', value=cogs_desc, inline=False)
# integrating trough uncategorized commands
commands_desc = ''
for command in self.bot.walk_commands():
# if cog not in a cog
# listing command if cog name is None and command isn't hidden
if not command.cog_name and not command.hidden:
commands_desc += f'{command.name} - {command.help}\n'
# adding those commands to embed
if commands_desc:
emb.add_field(name='Not belonging to a module', value=commands_desc, inline=False)
# setting information about author
emb.add_field(name="About", value=f"The Bots is developed by Chriѕ#0001, based on discord.py.\n\
This version of it is maintained by {owner}\n\
Please visit https://github.com/nonchris/discord-fury to submit ideas or bugs.")
emb.set_footer(text=f"Bot is running {config.VERSION}")
# block called when one cog-name is given
# trying to find matching cog and it's commands
elif len(input) == 1:
# iterating trough cogs
for cog in self.bot.cogs:
# check if cog is the matching one
if cog.lower() == input[0].lower():
# making title - getting description from doc-string below class
emb = discord.Embed(title=f'{cog} - Commands', description=self.bot.cogs[cog].__doc__,
color=discord.Color.green())
# getting commands from cog
for command in self.bot.get_cog(cog).get_commands():
# if cog is not hidden
if not command.hidden:
emb.add_field(name=f"`{config.PREFIX}{command.name}`", value=command.help, inline=False)
# found cog - breaking loop
break
# if input not found
# yes, for-loops have an else statement, it's called when no 'break' was issued
else:
emb = discord.Embed(title="What's that?!",
description=f"I've never heard from a module called `{input[0]}` before :scream:",
color=discord.Color.orange())
# too many cogs requested - only one at a time allowed
elif len(input) > 1:
emb = discord.Embed(title="That's too much.",
description="Please request only one module at once :sweat_smile:",
color=discord.Color.orange())
else:
emb = discord.Embed(title="It's a magical place.",
description="I don't know how you got here. But I didn't see this coming at all.\n"
"Would you please be so kind to report that issue to me on github?\n"
"https://github.com/nonchris/discord-fury/issues\n"
"Thank you! ~Chris",
color=discord.Color.red())
# sending reply embed using our own function defined above
await send_embed(ctx, emb)
def setup(bot):
bot.add_cog(Help(bot))
except AttributeError as e:
owner = config.OWNER_NAME
OWNER_NAME = "your name or something"
import config