discord.py 托管在 heroku 上的 bot 无法上线

discord.py bot hosted on heroku wont go online

我决定使用 heroku 运行 我的机器人 24/7。我部署了,看到我的 dyno 运行ning,没有错误,它甚至被打开了。我预计机器人会因为部署而上线,但它只是保持离线状态。

这是我的机器人代码:

import discord
import os
import asyncio
import random
from discord.ext import commands, tasks
from itertools import cycle

TOKEN = 'XXXXX'

client = commands.Bot(command_prefix = '/')

client.remove_command('help')

status = cycle(['Helping my Creator!', 'Moderating this server. smh'])

messages = 0

@client.event
async def on_ready():
    change_status.start()
    print('Bot has connected.')

@client.event
async def on_message(message):
    global messages
    messages +-1

    bad_words = [(just a list of bad words)]

    for word in bad_words:
        if message.content.count(word) > 0:
            print('Someone said a bad word')
            await message.channel.purge(limit = 1)
    await client.process_commands(message)

@tasks.loop(minutes = 5)
async def change_status():
    await client.change_presence(activity = discord.Game(next(status)))

@client.command()
async def cheese(ctx):
    responses = ["Here's some Parmesan.:cheese:",
                 "Here's some Pecorino.:cheese:",
                 "Here's some Manchego.:cheese:",
                 "Here's some Grana-Padano.:cheese:",
                 "Here's some Cheddar.:cheese:",
                 "Here's some Gouda.:cheese:",
                 "Here's some Harvati.:cheese:",
                 "Here's some Gruyere.:cheese:",
                 "Here's some Gorgonzola.:cheese:",
                 "Here's some Stilton.:cheese:",
                 "Here's some Roquefort.:cheese:",
                 "Here's some Danish Blue.:cheese:",
                 "Here's some Brie.:cheese:",
                 "Here's some Camembert.:cheese:",
                 "Here's some Double Creme White.:cheese:",
                 "Here's some Cream Cheese.:cheese:",
                 "Here's some Feta.:cheese:",
                 "Here's some Mozzarella.:cheese:",
                 "Here's some Burrata.:cheese:",
                 "Here's some Chevre.:cheese:",
                 "Here's some Goat Brie.:cheese:",
                 "Here's some Blue Goat Cheese.:cheese:"]
    await ctx.send(random.choice(responses))

 @client.command()
 async def userinfo(ctx, member: discord.Member = None):
     member = ctx.author if not member else member

     embed = discord.Embed(colour = member.color, timestamp = 
     ctx.message.created_at)

     embed.set_author(name = f"User info - {member}")
     embed.set_thumbnail(url = member.avatar_url)
     embed.set_footer(text = f"Requested by {ctx.author}", icon_url = 
     ctx.author.avatar_url)

     embed.add_field(name = "ID:", value = member.id)
     embed.add_field(name = "Guild name:", value = member.display_name)

     embed.add_field(name = "Created at:", value 
     member.created_at.strftime("%a, %d %B %Y, %I:%M %p UTC"))
     embed.add_field(name = "Joined at:", value = 
     member.joined_at.strftime("%a, %d %B %Y, %I:%M %p UTC"))

     embed.add_field(name = "Bot?", value = member.bot)

     await ctx.send(embed = embed)

client.run(TOKEN)

这是我的过程文件:

worker: python3 modbotv4.py

我的 requirements.txt 文件:

git+https://github.com/Rapptz/discord.py
dnspython==1.16.0
PyNaCl==1.3.0
async-timeout==3.0.1

还有我的 runtime.txt 文件:

python-3.8.3

如果我应该在任何文件中添加任何内容以使我的机器人上线,请告诉我。

我自己 运行 时,您提供的代码会抛出一些错误

1st 在第 69 和 70 行,最后一个 @client.command() 和异步定义缩进 1 space,但这可能只是粘贴到堆栈溢出时的错误


 @client.command()
 async def userinfo(ctx, member: discord.Member = None):
^

第二个是少了一个等号

embed.add_field(name = "Created at:", value 
member.created_at.strftime("%a, %d %B %Y, %I:%M %p UTC"))

它应该在哪里

embed.add_field(name = "Created at:", value =
                                            ^ equals sign
member.created_at.strftime("%a, %d %B %Y, %I:%M %p UTC"))

代码然后运行没问题

抱歉,拖了这么久