我决定使用heroku运行我的机器人24/7。我部署了,看到我的测功机运行了,没有错误,甚至被打开了。我希望该机器人会因为部署而联机,但是它只是保持脱机状态。
这是我的机器人代码:
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)
这是我的procfile:
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
如果有什么我应该添加任何文件以使我的机器人上线的话,请告诉我。
答案 0 :(得分:0)
自己运行时,您提供的代码会引发一些错误
第一个位于69和70行,最后一个@ client.command()和async定义缩进1个空格,但这在粘贴到堆栈溢出中时可能只是一个错误
@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"))
然后代码可以正常运行
很抱歉花了这么长时间