Так что мне нужно сохранить список объектов сообщений в файл, чтобы их можно было потом удалить.Проблема в том, что объект сообщения экспортируется в формате <discord.message.Message object at 0x00000203B2915C10>
, теперь это работает нормально, когда данные читаются прямо из списка, но когда эти данные сохраняются в CSV и затем загружаются снова, Python отказывается распознавать данные как сообщение.объект и выдает ошибки, когда я пытаюсь удалить его.
async def LoadHistory():
global theHistory#[[messageobject,killinterval,clock],[messageobject,killinterval,clock]]
del theHistory[:]
with open('history.csv','r') as fHnd:
reader = csv.reader(fHnd)
for row in reader:
theHistory.append([row[0],int(row[1]),int(row[2])])
async def SaveHistory():
global theHistory
np.savetxt('history.csv', theHistory, fmt='%s', delimiter=',')
и подпрограмма удаления
async def Main_Loop(interval):
global theMessages#[[message,interval,killinterval,clock,intArg,killArg],[message,interval,killinterval,clock,intArg,killArg]]
global theServer
global theChannel
global theHistory#[[messageobject,killinterval,clock],[messageobject,killinterval,clock]]
while True:
curTime = round(time.time())
#--------------DELETE OLD MESSAGES
n=0
for historyData in theHistory:
messageObject=historyData[0]
killInterval=historyData[1]
killTime=historyData[2]
print(theHistory)
if curTime-killTime > killInterval:#if the timer is up
print("delete time")
print(messageObject)
await dBot.change_presence(game=discord.Game(name="Housekeeping....."))
await dBot.delete_message(messageObject)
await dBot.change_presence(game=discord.Game(name=DEFAULT_STATUS))
del theHistory[n]
await SaveHistory()
n+=1
await asyncio.sleep(interval)#pause
и трассировка
delete time
<discord.message.Message object at 0x00000203B2915C10>
Task exception was never retrieved
future: <Task finished coro=<Main_Loop() done, defined at C:\Users\user\Documents\Python\Captain Obvious\captainObvious1.21.py:183> exception=AttributeError("'str' object has no attribute 'channel'",)>
Traceback (most recent call last):
File "C:\Users\user\Documents\Python\Captain Obvious\captainObvious1.21.py", line 222, in Main_Loop
await dBot.delete_message(messageObject)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 1261, in delete_message
channel = message.channel
AttributeError: 'str' object has no attribute 'channel'
Заранее спасибо<3 </p>