首页 > 解决方案 > 删除高级命令对我不起作用

问题描述

import os
import discord
import json
from discord.ext import commands, check

@bot.command()
async def removepremium(ctx, user : discord.Member):
    if ctx.author.id != 475975102576590849: #put your user id on discord here
        return

    with open("premium_users.json") as f:
        premium_users_list = json.load(f)

    if user.id in premium_users_list:
      premium_users_list.pop(user.id)
    else:
        await ctx.send(f"{user.mention} is not in the list, so they cannot be removed!")
        return

    with open("premium_users.json", "w+") as f:
        json.dump(premium_users_list, f)

    await ctx.send(f"{user.mention} has been removed!")

removepremium 不起作用我收到此错误 -

忽略命令 removepremium 中的异常:文件“main.py”,第 247 行,在 removepremium premium_users_list.pop(user.id) IndexError:弹出索引超出范围

标签: pythondiscorddiscord.py

解决方案


您要做的就是将 .pop 更改为 .remove

premium_users_list.remove(user.id)


推荐阅读