【发布时间】:2021-12-04 19:39:36
【问题描述】:
我的 discord 机器人中有一个日志系统,我想制作一个允许您忽略频道的系统,但我坚持使用它。 目前我有这个代码:
cursor=db.cursor(dictionary=True)
cursor.execute(f"SELECT * FROM `logexclude` WHERE server={int(before.guild.id)}")
excluded = cursor.fetchall()
for i in excluded:
if before.channel.id in i[1]: return
excluded 是一个列表,它看起来像这样:
[{'server': 890248334542008321, 'channel_ids': 890248758875533322, 'user_ids': 0, 'role_ids': 0}]
但是,当我尝试访问它的第一个元素 (excluded[0]) 时,它只会给我一个错误:
if before.channel.id in i[1]: return
TypeError: 1
【问题讨论】:
-
如果
excluded中的每个元素都是dictionary,那么你怎么能期望像list(i[1]) 那样解析它们。您应该使用i[channel_ids]之类的键解析它们。默认情况下,它们应该是list,但是当调用db.cursor()函数时,dictionary标志设置为True,即cursor=db.cursor(dictionary=True)。 -
你所说的“字典元素”到底是什么意思?
标签: python mysql discord.py