import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=".")
bot.remove_command('help')
total_commands = 0
total_usage = 0
total_users = 0
@bot.event
async def on_ready():
print("Bot is ready")
@bot.command()
async def help(ctx):
await ctx.send("Which help page? say 'commands' for commands 'home' for home page")
def check(msg):
return msg.author == ctx.author and msg.channel == ctx.channel and \
msg.content.lower() in ["home", "commands"]
msg = await bot.wait_for("message", check=check)
if msg.content.lower() == "home":
embed = discord.Embed(title="**Home Menu**", description=f"Total usage: {total_usage}\n\nTotal Commands Ran: {total_commands}\n\nTotal Users: {total_users}", color=discord.Color.from_rgb(0, 191, 255))
embed.set_footer(icon_url=f"{ctx.author.avatar_url}", text="Seppuku V2.0")
await ctx.send(embed=embed)
total_commands = total_commands + 1
elif msg.content.lower() == "commands":
embed = discord.Embed(title="**Coming Soon**", description="**Coming Soon**", color=discord.Color.from_rgb(0, 191, 255))
embed.set_footer(icon_url=f"{ctx.author.avatar_url}", text="Seppuku V2.0")
await ctx.send(embed=embed)
total_commands = total_commands + 1
Ошибка, которую я получаю, связана со строкой total_commands = total_commands + 1
:
локальная переменная «total_commands», определенная в охватывающей области в строке 8, на которую ссылается перед назначением
Если бы кто-то мог помочь, было бы здорово :)
total_commands
во внешней области. вы можете захотеть внести это в функцию, используяglobal total_commands
, но, честно говоря, когда именно вам нужно это сделать, это смущает даже меня. Тем не менее, это не ошибка в строке выше, так что... странно. Попробуйте поменять его наtotal_commands += 1
вместо этого? - person ch4rl1e97   schedule 27.05.2021