ctx 和公会参数在命令中不起作用并显示错误



我有命令custom_role:

@Bot.command()
async def custom_role(ctx, colour: str, *, name: str):
colour = discord.Color(value=int(colour, 16))
print(colour)
await open_account(сtx.author)
user = ctx.author
bal = await update_bank(user)
if 1000>bal:
await ctx.send("You don't have that much money")
return
await ctx.guild.create_role(name = name, colour=colour)
await update_bank(user, -1000, "wallet")
role = discord.utils.get(guild.roles, name = name)

await user.add_roles(role)
emb = discord.Embed(description = "You bought custom role for a week!", color = 0x2ecc71)
await ctx.send(embed = emb)
await asyncio.sleep(604800)
await user.remove_roles(role)

但我有两个错误:

未定义的变量"сtx">

未定义的变量"公会">

完整回溯:从 exc 引发 CommandInvokeError(exc) discord.ext.command.errors.CommandInvokeError: 命令引发异常: NameError: 名称 'сtx' 未定义

这很奇怪,因为在其他命令中ctx参数运行良好

此命令中使用了帮助程序函数:

async def open_account(user):

users = await get_bank_data()

if str(user.id) in users:
return False
else:
users[str(user.id)] = {}
users[str(user.id)]["wallet"] = 0
with open("mainbank.json", "w") as f:
json.dump(users, f)
return True

async def update_bank(user, change = 0, mode = "wallet"):
users = await get_bank_data()
users[str(user.id)][mode] += change
with open("mainbank.json", "w") as f:
json.dump(users, f)
bal = users[str(user.id)]["wallet"]
return bal
async def get_bank_data():
with open("mainbank.json", "r") as f:
users = json.load(f)
return users 

如果您知道如何解决此问题,请回答

命令应该是这样的:

@Bot.command()
async def custom_role(ctx, colour: str, *, name: str):
colour = discord.Color(value=int(colour, 16))
print(colour)
user = ctx.author
await open_account(user)
bal = await update_bank(user)
if 1000>bal:
await ctx.send("You don't have that much money")
return
await ctx.guild.create_role(name = name, colour=colour)
await update_bank(user, -1000, "wallet")
role = discord.utils.get(ctx.guild.roles, name = name)
await user.add_roles(role)
emb = discord.Embed(description = "You bought custom role for a week!", color = 0x2ecc71)
await ctx.send(embed = emb)
await asyncio.sleep(604800)
await user.remove_roles(role)

因为我忘了在"公会角色"之前加上"ctx">

最新更新