@commands.command(aliases=['uptime', 'up'])
async def status(self, ctx):
timeUp = time.time() - self.bot.startTime
hours = timeUp / 3600
minutes = (timeUp / 60) % 60
seconds = timeUp % 60
admin = self.bot.AppInfo.owner
users = 0
channel = 0
if len(self.bot.commands_used.items()):
commandsChart = sorted(self.bot.commands_used.items(), key=lambda t: t[1], reverse=False)
topCommand = commandsChart.pop()
commandsInfo = '{} (Top-Command: {} x {})'.format(sum(self.bot.commands_used.values()), topCommand[1], topCommand[0])
else:
commandsInfo = str(sum(self.bot.commands_used.values()))
for guild in self.bot.guilds:
users += len(guild.members)
channel += len(guild.channels)
embed = discord.Embed(color=ctx.me.top_role.colour)
embed.set_footer(text='UwU')
embed.set_thumbnail(url=ctx.me.avatar_url)
embed.add_field(name='Admin', value=admin, inline=False)
embed.add_field(name='Uptime', value='{0:.0f} Stunden, {1:.0f} Minuten und {2:.0f} Sekunden\n'.format(hours, minutes, seconds), inline=False)
embed.add_field(name='Beobachtete Benutzer', value=users, inline=True)
embed.add_field(name='Beobachtete Channel', value=channel, inline=True)
embed.add_field(name='Ausgeführte Commands', value=commandsInfo, inline=True)
embed.add_field(name='Bot Version', value=self.bot.botVersion, inline=True)
embed.add_field(name='Discord.py Version', value=discord.__version__, inline=True)
embed.add_field(name='Python Version', value=platform.python_version(), inline=True)
embed.add_field(name='Betriebssystem', value=f'{platform.system()} {platform.release()} {platform.version()}', inline=False)
await ctx.send('**:information_source:** Informationen über diesen Bot:', embed=embed)我需要关于这个命令的帮助
我得到以下错误:[10.02.2021 16:31:10][WARN] Unknown error:[0mCommand raised an exception: AttributeError: 'Bot' object has no attribute 'startTime'
我检查了所有的进口商品..我的导入是
从discord.ext导入不一致导入命令导入datetime导入json导入aiohttp导入随机导入ast从pymongo导入MongoClient从discord.utils导入get从pytz导入时区导入os导入数学导入itertools从discord.ext.commands导入CommandNotFound,MissingPermissions,MessageNotFound导入asyncio
发布于 2021-02-15 20:24:57
discord.ext.commands.Bot不保存机器人启动的日期。但是,您可以很容易地手动完成此操作。在主文件的on_ready函数中,创建一个bot变量并保存当前的日期时间。确保你也导入了它!
如果你不知道,机器人变量是这样声明的:bot.your_var_name = value。但是要小心,因为您可能会覆盖某些内容。在您的情况下,您可以尝试;
import datetime
'''
Import everything else you need and
make sure to declare the bot client
'''
@bot.event
async def on_ready():
bot.start_time = datetime.datetime.now()然后,您可以在该文件之外使用bot.start_time。例如,在齿轮中,它将是self.bot.start_time。
在您的代码中,我建议使用datetime而不是time,它更容易使用。
https://stackoverflow.com/questions/66140066
复制相似问题