微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

托管在 repl.it 上的 Python discord bot 无法正常工作

如何解决托管在 repl.it 上的 Python discord bot 无法正常工作

所以,我正在 repl.it 上开发一个机器人,但我不明白为什么我的代码不起作用......

我有一个每 24 小时调用一次的循环异步函数

@tasks.loop(hours=24)
async def send_plot():
  await bot.wait_until_ready()
  if str(datetime.Now(tz).strftime('%Y-%m-%d')) not in db['Date']:
    append_db('Date',str(datetime.Now(tz).strftime('%Y-%m-%d')))
---------------------------------------------------------------------------- # starting here
    print('...')
    for key in db.keys():
      append_db(key,db[key][len(db[key]) - 1])
---------------------------------------------------------------------------- # ending here
  plotting()
  message_channel = bot.get_channel(int(channel_id))
  await message_channel.send(file=discord.File('plot.png'))

因此,出于未知原因,这两行之间没有任何工作。我试图自己弄清楚,但我已经厌倦了,因为没有任何作用。这里发生了某种神奇的事情......

这是 append_db 函数

def append_db(key,value):
    clone = db[key]
    clone.append(value)
    db[key] = clone

不知道为什么,但这是让我将信息保存到 repl.it 数据库的唯一方法

解决方法

我还尝试在 repl.it 上创建一个 Discord bot,一个基本的 bot 可以在 Repl.it 上运行,但是当您变得更高级(如音乐机器人)时,repl.it 在运行代码时会出现一些问题。我建议在我打开的终端/命令提示符本地运行它,然后输入 python "file location" 或者如果您安装了 python 3,您可以尝试 python3 "file location" 并且您将文件位置替换为您计算机上的文件位置.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。