我开始在一个cPanel (o2switch)上托管我的不和谐机器人,但是我不知道如何运行这个机器人。我必须为我的应用程序定义一个入口点,但我不知道它应该是什么。我试图将它设置为一个只返回"Launched!"的函数,但这是行不通的。
# imports
def application():
return "Launched!"
# bot code有人知道我应该为我的机器人运行添加什么代码吗?
编辑:添加“跑步者”的东西。机器人仍然没有启动,但我有一个日志:
App 16078 output: /opt/passenger-5.3.7-5.el7.cloudlinux/src/helper-scripts/wsgi-loader.py:26: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
App 16078 output: import sys, os, re, imp, threading, signal, traceback, socket, select, struct, logging, errno
App 16078 output: [ pid=16078, time=2020-01-15 16:18:24,002 ]: PyNaCl is not installed, voice will NOT be supported
App 16078 output: [ pid=16078, time=2020-01-15 16:18:24,033 ]: WSGI application raised an exception!
App 16078 output: Traceback (most recent call last):
App 16078 output: File "/opt/passenger-5.3.7-5.el7.cloudlinux/src/helper-scripts/wsgi-loader.py", line 199, in main_loop
App 16078 output: socket_hijacked = self.process_request(env, input_stream, client)
App 16078 output: File "/opt/passenger-5.3.7-5.el7.cloudlinux/src/helper-scripts/wsgi-loader.py", line 333, in process_request
App 16078 output: result = self.app(env, start_response)
App 16078 output: File "/home/bist1484/virtualenv/bot/3.7/lib/python3.7/site-packages/discord/client.py", line 598, in run
App 16078 output: return future.result()
App 16078 output: File "/home/bist1484/virtualenv/bot/3.7/lib/python3.7/site-packages/discord/client.py", line 579, in runner
App 16078 output: await self.start(*args, **kwargs)
App 16078 output: File "/home/bist1484/virtualenv/bot/3.7/lib/python3.7/site-packages/discord/client.py", line 542, in start
App 16078 output: await self.login(*args, bot=bot)
App 16078 output: TypeError: login() takes 2 positional arguments but 4 positional arguments (and 1 keyword-only argument) were given发布于 2020-01-16 18:06:01
我自己在cPanel上托管我的机器人。我会帮你托管你的机器人。确保您的bot位于主目录中,其权限设置为755。
您需要一个开始脚本和一个停止脚本。在您的public_html的cgi-bin中创建一个新的文件,您就可以在yourmaindomain.com/cgi/ startbot.py上启动机器人,考虑到您将startbot.py的开始脚本命名为startbot.py。在start脚本中放置以下代码:
#!/usr/bin/python3.6
import os, subprocess, signal
print("Content-Type: text/html\n\n")
counter = 0
p = subprocess.Popen(['ps', '-u', 'username'], stdout=subprocess.PIPE)
# must match your username --------^^^^^^^^
out, err = p.communicate()
for line in out.splitlines():
if 'heliobot.py'.encode('utf-8') in line:
# ^^^^^^^^^^^----- this has to match the filename of your bot script
counter += 1
print("Bot already running.")
if counter == 0:
subprocess.Popen("/home/username/heliobot.py")
# ^^^^^^^^-- be sure to update it to your username
print("Bot started!")对于停止脚本,您可以在同一个cgi-bin中创建一个stopbot.py文件,在该文件中您可以在你的maindomain.com/cgi/topbot.py上停止机器人操作,在脚本中放置以下代码:
!/usr/bin/python3.6
import os, subprocess, signal
print("Content-Type: text/html\n\n")
counter = 0
p = subprocess.Popen(['ps', '-u', 'username'], stdout=subprocess.PIPE)
# must match your username --------^^^^^^^^
out, err = p.communicate()
for line in out.splitlines():
if 'heliobot.py'.encode('utf-8') in line:
# ^^^^^^^--- this has to match the filename of your loop
counter += 1
pid = int(line.split(None, 1)[0])
print("Stopping bot.")
os.kill(pid, signal.SIGTERM)
if counter == 0:
print("Already stopped.")用托管提供商的Python替换第一行,即shebang。确保安装了所使用的模块,否则请求主机为您安装它。此外,确保所有这些文件的权限为755,否则将得到内部服务器错误。。
请记住替换我在脚本中突出显示的那些参数。自从我开始开发,我就是这样在cPanel免费主机上托管我的机器人的。我从来没有钱得到退伍军人津贴,所以这是最好的,似乎是我唯一的选择。(出于各种原因,我不喜欢Heroku和其他应用程序主机)。希望这能帮助和解决你的问题!如果你还有什么需要帮助的话,就把它写下来,我会尽力帮你的。:)
致以敬意,
萨扬·巴塔查里亚。
发布于 2020-01-15 16:44:43
cPanel是为网络托管而设计的,而不是为不和谐的机器人等应用程序设计的。
应用程序入口点用于支持WSGI的web应用程序框架。它不适用于不和谐的机器人。
发布于 2020-01-15 14:54:02
你需要打电话给Client.run。具体来说,您需要准备一个可以传递给其他应用程序的部分函数:
from functools import partial
from discord import Client
client = Client()
@client.event
async def on_message(message):
print(message.content)
runner = partial(client.run, "your token") # runner() then starts the bothttps://stackoverflow.com/questions/59753817
复制相似问题