python - 删除高级命令对我不起作用
问题描述
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:弹出索引超出范围
解决方案
您要做的就是将 .pop 更改为 .remove
premium_users_list.remove(user.id)
推荐阅读
- php - WordPress 自定义帖子类型分页返回 404 页面错误
- mysql - 删除插入前的 MySQL
- javascript - JAWS / IE11 中的 Keydown 事件未正确触发
- flutter - [Flutter]SliverAppBar在NestedScrollView中向下滚动时如何保持flexibleSpace展开?
- android - 他从哪里拿的号码?自定义数字键盘 (Android Kotlin)
- reactjs - TS1128:需要声明或声明(文件结尾)
- javascript - twitter api - nodejs问题
- ios - 作为 UIView 的子视图的程序化 UIButton 没有响应
- json - 无法在 JSON 邮递员中提取出勤数据
- java - 为什么这个 JPanel 在第一次查看后会删除所有项目?