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

时间:2021-03-23 02:14:03

标签: python asynchronous discord repl.it

所以,我正在 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 数据库的唯一方法。

1 个答案:

答案 0 :(得分:-1)

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

相关问题