【问题标题】:why is my discord.py bot is not going online after deploying on heroku?为什么我的 discord.py 机器人在 heroku 上部署后没有上线?
【发布时间】:2021-01-19 08:15:59
【问题描述】:

我的 bot.py 的代码是:

import discord
from discord.ext import commands
import random
from discord.ext.commands import bot
import asyncio
import requests
import os

client = commands.Bot(command_prefix = "!")
.. Command's and stuff..
bot.run(str(os.environ.get('DISCORD_TOKEN')))

我的 requirements.txt 包含:

discord.py
requests

我的 Procfile 包括:

worker: python3 bot.py

我按照所有步骤通过 git 进行部署,它成功部署但仍然不在线。

【问题讨论】:

  • 从heroku 提供日志,另外,您是否通过缩放来启动测功机?

标签: heroku bots discord.py


【解决方案1】:

因为你的os.environ,你的机器人没有上线。它没有任何 get 方法,因为它是一个 Mapping 对象。使用方法如下:

bot.run(os.environ['DISCORD_TOKEN'])

PS:你有一些不必要的导入,比如from discord.ext.commands import bot。您应该只导入您需要的内容(例如,from os import environ 而不是 import os)。

【讨论】:

  • 另外,他的 requirements.txt 并不全面:缺少版本号。请执行pip freeze 并将内容复制并粘贴到该文件中,或者您也可以执行pip freeze > requirements.txt
猜你喜欢
  • 2020-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-14
  • 2021-05-28
  • 2021-12-05
  • 2021-07-11
  • 2022-01-16
相关资源
最近更新 更多