这是主要代码(注意,我故意排除了这个问题的bot令牌,这不是错误的来源(:
from discord.ext import commands
from discord.utils import get
import random
import asyncpraw
import os
import sys
bot = commands.Bot(command_prefix = "!")
@bot.command()
async def load(ctx, extension):
bot.load_extension(f'cogs.{extension}')
@bot.command()
async def unload(ctx, extension):
bot.unload_extension(f'cogs.{extension}')
@bot.command()
async def reload(ctx, extension):
bot.unload_extension(f'cogs.{extension}')
bot.load_extension(f'cogs.{extension}')
for filename in os.listdir(r".cogs"):
if filename.endswith('.py'):
bot.load_extension(f'cogs.{filename[:-3]}')
bot.run(<TOKEN>)
这是我创建的一个齿轮:
from discord.ext import commands
import discord
class Help(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print('Help Cog Online')
@commands.command()
async def helpme(self, ctx):
emb = discord.Embed(title = 'Help Page!', color = 0xeb4034)
emb.add_field(name = "====================================",
value = "-----------------------------------------------------------", inline= False)
emb.add_field(name = "BASIC COMMANDS", value = 'Basic', inline= False)
emb.add_field(name = "Hello", value = '>hello', inline= True)
emb.add_field(name = "Rick", value = '>rick', inline= True)
emb.add_field(name = "Counter +1", value = '>inc', inline= True)
emb.add_field(name = "Counter -1", value = '>dec', inline= True)
emb.add_field(name = "Show Count", value = '>showc', inline= True)
emb.add_field(name = "Reset Counter", value = '>reset', inline= True)
emb.add_field(name = "====================================",
value = "-----------------------------------------------------------", inline= False)
emb.add_field(name = "REDDIT COMMANDS", value = 'Share SR Posts', inline= False)
emb.add_field(name = "Memes", value = '>meme', inline= True)
emb.add_field(name = "IndianDankMemes", value = '>dankmeme', inline= True)
emb.add_field(name = "ChemicalReactionGifs", value = '>reaction', inline= True)
emb.add_field(name = "Facts", value = '>fact', inline= True)
emb.add_field(name = "PerfectTiming", value = '>wowpics', inline= True)
emb.add_field(name = "Cute Dogs", value = '>doggie', inline= True)
emb.add_field(name = "Cute Cats", value = '>kitty', inline= True)
emb.add_field(name = "Cute Ducks", value = '>duckie', inline= True)
emb.add_field(name = "Aww", value = '>aww', inline= True)
emb.add_field(name = "====================================",
value = "-----------------------------------------------------------", inline= False)
emb.add_field(name = "SASS COMMANDS", value = 'Be sassy', inline= False)
emb.add_field(name = "Roast Someone", value = '>roast @user', inline= True)
emb.add_field(name = "Slap Someone", value = '>slap @user', inline= True)
await ctx.send(embed = emb)
def setup(bot):
bot.add_cog(Help(bot))
我不太确定路径是否正确,因为我正在使用GitHub,而且我对它有点陌生。。。当我使用GitHub并在Heroku上托管时,这个机器人不会上线。然而,当我在本地运行这些文件时,它确实会运行。我已经尝试过GitHub的各种路径,似乎都没有什么不同。注意:我的GitHub repo 中有所需的Procfile和需求文件
编辑:Heroku日志
-----> Using buildpack: heroku/python
-----> Python app detected
-----> Using Python version specified in runtime.txt
! Python has released a security update! Please consider upgrading to python-3.8.13
Learn More: https://devcenter.heroku.com/articles/python-runtimes
-----> No change in requirements detected, installing from cache
-----> Using cached install of python-3.8.5
-----> Installing pip 21.3.1, setuptools 57.5.0 and wheel 0.37.0
-----> Installing SQLite3
-----> Installing requirements with pip
-----> Discovering process types
Procfile declares types -> worker
-----> Compressing...
Done: 54.8M
-----> Launching...
Released v6
https://test-0510.herokuapp.com/ deployed to Heroku
编辑2:这是我在构建后点击"查看"得到的
编辑3:我相信这些是我的日志:
2022-04-09T07:45:32.083418+00:00 app[api]: Deploy fd1e17a7 by user ishnkshyp@gmail.com
2022-04-09T07:45:32.083418+00:00 app[api]: Release v10 created by user ishnkshyp@gmail.com
2022-04-09T07:45:32.643569+00:00 heroku[worker.1]: State changed from crashed to starting
2022-04-09T07:45:35.329607+00:00 heroku[worker.1]: Starting process with command `python ChimkenBotTest.py`
2022-04-09T07:45:35.935258+00:00 heroku[worker.1]: State changed from starting to up
2022-04-09T07:45:37.115367+00:00 app[worker.1]: Traceback (most recent call last):
2022-04-09T07:45:37.115431+00:00 app[worker.1]: File "ChimkenBotTest.py", line 25, in <module>
2022-04-09T07:45:37.115679+00:00 app[worker.1]: for filename in os.listdir(r"ChimkenBot/cogs"):
2022-04-09T07:45:37.115760+00:00 app[worker.1]: FileNotFoundError: [Errno 2] No such file or directory: 'ChimkenBot/cogs'
2022-04-09T07:45:37.282695+00:00 heroku[worker.1]: Process exited with status 1
2022-04-09T07:45:37.403838+00:00 heroku[worker.1]: State changed from up to crashed
2022-04-09T07:45:37.453014+00:00 heroku[worker.1]: State changed from crashed to starting
2022-04-09T07:45:40.235384+00:00 heroku[worker.1]: Starting process with command `python ChimkenBotTest.py`
2022-04-09T07:45:40.898743+00:00 heroku[worker.1]: State changed from starting to up
2022-04-09T07:45:40.000000+00:00 app[api]: Build succeeded
2022-04-09T07:45:41.890588+00:00 app[worker.1]: Traceback (most recent call last):
2022-04-09T07:45:41.890609+00:00 app[worker.1]: File "ChimkenBotTest.py", line 25, in <module>
2022-04-09T07:45:41.890668+00:00 app[worker.1]: for filename in os.listdir(r"ChimkenBot/cogs"):
2022-04-09T07:45:41.890686+00:00 app[worker.1]: FileNotFoundError: [Errno 2] No such file or directory: 'ChimkenBot/cogs'
2022-04-09T07:45:42.039935+00:00 heroku[worker.1]: Process exited with status 1
2022-04-09T07:45:42.174315+00:00 heroku[worker.1]: State changed from up to crashed```
好吧,我想明白了。问题出现在我指定的路径中。我本来打算参加./cogs
我把它改成了cogs
,它起作用了。