我想让我的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/,但是我会在这里发布任何文件,这样就更容易了。
发布于 2019-05-05 14:51:52
从评论中的讨论中,我和OP发现了哪里出了问题:
client.run
应该是bot.run
requests
不是Python标准库的一部分,而asyncio
是标准库的一部分。解决上述问题似乎已经解决了这些问题。
辅助代码检查将删除冗余行,如
from discord.ext.commands import bot
(无论如何,它会被bot = Bot(...)
覆盖)。
代码中没有使用asyncio
和requests
模块,但我将给您带来疑问,并假定您正在计划使用它们。如果不是,从代码中删除它们(如果适用的话,从requirements.txt中删除)。这节省了建造机器人的时间。
https://stackoverflow.com/questions/55992696
复制相似问题