我正在用discord.py制作一个discord机器人,它依赖sqlite3数据库来存储公会信息。在我的电脑上制作机器人时,一切都进行得很顺利,我没有收到错误,但是当我上传到repl.it时,它突然出现了错误。为什么会这样
import time
import requests
import random
import asyncio
import datetime
import discord
import sqlite3
import randfacts
from discord.ext import tasks, commands
class FactsCog(commands.Cog, name = "Facts"):
def __init__(self, bot):
self.bot = bot
self.fotd.start()
@tasks.loop(seconds=20.0)
async def fotd(self):
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(f"SELECT channel_id FROM main")
channels = cursor.fetchall()
for ID in channels:
fact = randfacts.getFact()
channel = self.bot.get_channel(int(ID[0]))
embed = discord.Embed(colour = 0x4f92ff, title = "Fact Of The Day", description = fact)
embed.set_thumbnail(url = 'https://cdn.discordapp.com/attachments/811504534177579038/820069055444156436/TriviaTops.png')
embed.set_footer(text = "Fact Of The Day - Trivia Tops", icon_url = 'https://cdn.discordapp.com/attachments/811504534177579038/820069055444156436/TriviaTops.png')
await channel.send(embed = embed)
@fotd.before_loop
async def before_start(self):
await self.bot.wait_until_ready()
def setup(bot):
bot.add_cog(FactsCog(bot))
print("Facts cog loaded!")
这是我的代码,我确信没有任何问题,因为它在我的PC上运行得很好,但是repl.it上出现了错误“sqlite3 OperationalError:no-This table:main”
感谢您的阅读,如果您能详细介绍一下您的答案,我将不胜感激,因为我昨天才开始学习python
repl.it环境中不存在main.sqlite文件。为了解决这个问题,您可以使用
:memory:
而不是使用文件在内存中创建数据库请注意,这也意味着当程序完成执行时,db将消失
相关问题 更多 >
编程相关推荐