为什么我的discord.py机器人在heroku上部署后没有上线



我的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进行了部署,它成功地部署了,但仍然没有上线。

由于您的os.environ,您的机器人无法联机。它没有任何get方法,因为它是一个Mapping对象。以下是使用方法:

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

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