如何解决所以我正在尝试这样做,以便您可以看到已在机器人上运行的命令数量,但我遇到了错误
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**",text="Seppuku V2.0")
await ctx.send(embed=embed)
total_commands = total_commands + 1
我得到的错误是 total_commands = total_commands + 1
行:
在赋值前引用的第 8 行的封闭作用域中定义的局部变量“total_commands”
如果有人能帮忙那就太好了:)
解决方法
尝试在导入后将 total_commands 变量的声明/初始化放在第 1 行。
rom discord.ext import commands
total_commands=0
bot = commands.Bot(command_prefix=".")
bot.remove_command('help')
total_usage = 0
total_users = 0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。