我正试图免费托管我的discord.py僵尸程序,听说Heroku是一个不错的选择。我的dyno运行良好,并且已打开,但是在部署时,我的机器人无法联机。我没有任何错误,它表示已部署,但我的机器人从未上线。
我已经尝试过重新生成机器人令牌,并将其放入我的Heroku应用程序中,但仍然无法正常工作。
import discord
from discord.ext import commands
from discord.ext.commands import bot
import asyncio
import requests
import os
description = '''EchoBot by EchoNoahGaming'''
bot = commands.Bot(command_prefix='-', description=description)
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
async def announcement(ctx, *, args):
"""Announcement command!"""
embed=discord.Embed(title="Announcement", description=args, color=0x7700aa)
embed.set_footer(text="By EchoNoahGaming")
await ctx.send("@everyone", embed=embed)
client.run(str(os.environ.get('BOT_TOKEN')))
那是机器人代码。
我希望该机器人能够上线,因为没有错误,但是没有,并且保持脱机状态。
Procfile代码为
worker: python3 bot.py
requirements.txt的内容是
discord
asyncio
如果您还有其他需要,请告诉我。 GitHub链接为https://github.com/EchoNoahGaming/echobot/blob/master/,但我将在此处发布任何文件,这样更容易。
答案 0 :(得分:1)
从评论中的讨论中,我和OP找出了问题所在:
最后一行有一个错字:client.run
应该是bot.run
Requirements.txt文件应更改为
discord.py
requests
这是因为requests
不是Python标准库的一部分,而asyncio
是标准库的一部分。
解决以上问题似乎已经解决了问题。
辅助代码审查将是删除多余的行,例如
from discord.ext.commands import bot
(反正会被bot = Bot(...)
覆盖)。
代码中未使用asyncio
和requests
模块,但是我会给您带来疑问的好处,并假定您打算使用它们。如果没有,请从您的代码中删除它们(如果适用,也可以从requirements.txt中删除它们)。这样可以节省构建机器人的时间。