- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在用 python 编写一个 discord-bot,它可以在 IntelliJ 甚至终端上正常运行。
当我尝试让它在 linux 服务器上运行但未连接到它时,问题就开始了
# Called when a message is created and sent to a server.
# Parameters: message – A Message of the current message.
async def on_message(self, message):
print('Message from {0.author}: {0.content}'.format(message))
if message.author == self.user:
return
try:
await self.serverLog.on_message(message)
except Exception as e:
logger.exception(e)
try:
await self.werwolfBot.on_message(message)
except Exception as e:
logger.exception(e)
我通过命令行启动机器人
cd WerwolfBot
python3.6 -m werwolf &
disown
仍然通过 putty on_message 连接并且所有其他事件都会触发
当我断开与 linux 服务器的 ssh 连接时从那一刻起,它将触发其他事件,例如 on_voice_state_update 但不会触发 on_message
我希望我可以让机器人运行 disowned 并且它仍然可以工作。但它只适用于 on_message 以外的其他事件
最佳答案
参见 this answer on Unix SE关于 disown
实际做了什么。这是与您的问题相关的部分:
However note that it still is connected to the terminal, so if the terminal is destroyed (which can happen if it was a pty, like those created by xterm or ssh, and the controlling program is terminated, by closing the xterm or terminating the SSH connection), the program will fail as soon as it tries to read from standard input or write to standard output.
因此,一旦 print
尝试写入 stdout
,您的 on_message
就会失败。
我可以想到一些您可以尝试的解决方案:
nohup
(这是最交 key 的解决方案)stdout
(可能还有 stderr
)重定向到其他文件通过传递 file=
参数将
打印到 stdout
之外的地方logging
处理您的日志,不要将它们打印到stdout
(参见Setting Up Logging)关于python - discord.py on_message 在放弃 linux 作业并断开连接后停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56177079/
当我在 repl.it 上运行我的 discord 机器人时,出现错误。在错误中,我在下面看到了一些 HTML 代码。 CloudFlare 似乎阻止了我的机器人访问 Discord。这是什么原因造成
我计划使用 python 制作一个不和谐的机器人。 discord.py 和 discord.py[voice] 有什么区别? 最佳答案 discord.py 和 discord[voice] 之间的
我正在尝试编写一个脚本来检测用户是否以及何时将他们在 discord 上的名称从“bob”更改为“.bob”之类的名称,它会禁止此更改并将其保留为“bob”。 if (user.nickname.st
我想使用 Discord Bot 向用户发送私有(private)消息。 用户与机器人不在同一台服务器上。 如果我可以使用 author.sendMessage,我该如何初始化(查找)作者变量? 我可
我正在尝试将某人添加到特定服务器,然后通过 DM 只用不和谐 ID 表示该人。 它的工作方式是,有人在网站上使用 Discord OAuth2 登录自己,登录后他应该被添加到特定服务器,然后机器人应该
我无法弄清楚如何使用类似于 /giphy、/xivdb 等的实时“反馈”来实现斜杠命令。没有公共(public) API 吗? ?我正在使用 discord.py,但我想这对于这个问题来说并不重要。
我正在尝试使用 Discord Bot 在 discord 服务器上创建一个类别,但我无法在 Internet 上找到该方法或其他内容。我还看了“discord.js.org”。然后我认为没有任何可能
我正在为桌面创建灯,当我的麦克风在 Discord 上处于事件状态时,该灯将为绿色,当我的麦克风静音时,该灯将为红色。所以我想从不和谐中获取我的麦克风状态。但我不知道怎么做。 当我不在进行语音聊天时,
我已经看到了您允许某个角色使用命令的变体。但是,我试图实现完全相反的效果:如何禁止某个角色使用命令。 我搜索了堆栈溢出,没有找到答案,也没有在 discord.py 官方文档上找到答案。任何形式的帮助
我开发了自己的简单 discord bot(使用 discord.js)并将其部署到节点服务器。 一切正常。 现在我想为它添加更多功能。在开发过程中,我想在本地进行测试(当然)。 问题是:我可以在本地
我正在使用 Discord.js 创建一个基本的 Discord 机器人。当机器人第一次启动时,我运行 client.guilds.array()获取机器人当前订阅的所有公会的列表。我将其保存到其他程
我想为付费成员(member)提供 Discord 服务器。我想我可以让他们通过 Stripe 付款,向他们发送付款邀请,然后定期运行 Python 脚本,该脚本检查我的所有 Discord 成员是否
我试图向我的机器人添加一些新功能,但它最终没有工作,所以我删除了新代码,现在它不会响应任何命令。它仍然在线,但正如我之前所说,它完全没有响应。我已经查看了代码,但找不到问题。我对编码机器人还是个新手,
我正在编写一个建议机器人,它应该将玩家的建议发送到我服务器中的建议 channel ,并在建议 channel 中用一些表情符号使用react。 问题是使用“消息”作为消息参数会对发送到触发代码的消息
我想创建一个清除命令,如果 example .clear @user#0000 100 它将清除@user#0000 发送的最后 100 条消息。这是我的代码: @commands.comma
所以,我想为我的机器人创建一个命令,它可以从给定的消息 ID 中获取所有反应并将这三个类别存储到数组中,对于每个 react : react 的名称(例如:smile:) 使用react的用户(例如
我正在尝试在 discord.js 上制作一个简单的右舷系统,删除消息部分让我很困惑。目前,如果一条消息获得星号,则会在右舷 channel 创建一个嵌入,而且至关重要的是,页脚是原始消息的 ID。我
我最近启动了一个新的 discord.js 机器人,但出现“无效 token ”错误。这不可能是因为 async 功能,因为我只启动了机器人并且我有 0 个命令,上次发生这种情况是当我试图在 hero
我正在尝试向我的机器人添加一条命令,该命令会回复用户邀请到服务器的总人数 我的代码: if message.content.startswith('!invites'): totalInvit
我在一些服务器/公会中添加了一个 Discord 机器人。我可以使用此处提供的资源获得特定公会: https://discord.com/developers/docs/resources/guild
我是一名优秀的程序员,十分优秀!