【发布时间】:2021-04-28 09:37:00
【问题描述】:
这是我第一次做这些,对我来说太赤裸裸了。
我目前面临一个问题,使用 replit 的数据库(我很确定这是一本字典),我正在尝试创建一个生日循环,但我得到了这个 KeyError。
in get_raw raise KeyError(key)keyErorr: 310439746247589889
这来自的 KeyError 来自我要拆分的列表。是用空格分隔的两个数字,或者在这种情况下:
"bd043010" : "690738010903281734 310439746247589889"
这是我第一次看到这个错误,我不知道如何解决它。错误在第二个 for 循环之后开始。
@tasks.loop(hours = 23.9)
async def checkTodaysBirthdays():
announcements=client.get_channel(690738010903281734) #(671210942436081685)
date_md = today.strftime("%m%d")
date_BdY = today.strftime("%B %d, %Y")
# The stores the birthdays.
if "date_md" and "B_today" in db.keys():
print("db 'Birthdays announcments' working")
else:
db["date_md"] = date_md
db["B_today"] = True
# Checks if the birthday message has been sent today.
if (db["date_md"] == date_md and db["B_today"] == True):
# Sees if there is a birthday today.
if db.prefix(f"bd{date_md}") != ():
# if there is a birthday, loop through the guilds and send a custom message.
for guild in client.guilds:
B_days = []
print(guild.name + " " + str(guild.id)) # for testing
for x in db.prefix(f"bd{date_md}"):
splitX = db[x].split()
print(str(guild.id) + "\n" + splitX[0])
if splitX[0] == str(guild.id):
print(db[splitX[1]])
userId = int(db[splitX[1]])
B_days.append(client.get_user(userId).mention)
# The final message, orginized.
birthday_box = discord.Embed(
title = f"Birthdays Today: {date_BdY}",
description = ",".join(B_days),
color = discord.Color.red(),
)
birthday_box.set_thumbnail(url = "https://mpng.subpng.com/20180424/wcw/kisspng-birthday-cake-frosting-icing-emoji-christmas-cak-dumpling-5adf34378c5219.2963794415245773355748.jpg")
#birthday_box.set_footer(" :partying_face: :birthday: Be sure to say happy birthday to them! :confetti_ball: :tada:")
await announcements.send(embed=birthday_box)
#This will be updated later
print(f"birthdays today:{date_BdY}")
else:
print(f"No Birthdays Today!")
db["B_today"] = True
elif (db["date_md"] == date_md and db["B_today"] == False):
pass
else:
db["B_today"] = True
db["date_md"] = date_md
我不确定代码是错误的还是什么。此外,如果有任何我可以改进的地方,无论是关于此消息的代码或格式,请告诉我。谢谢。
【问题讨论】:
标签: python discord discord.py