python-3.x - Docker Container - 当 Python 脚本运行时,Discord Bot 挂起
问题描述
我已经在无头 Ubuntu 服务器上运行了这个脚本,但是当我尝试在具有网络桥接的 docker 容器中运行它时,安装了 python 包的它会将机器人登录,但永远不会进入“on_ready()”函数。
def main(ticker: str):
import discord
import asyncio
import yaml
filename = 'config.yaml'
with open(filename) as f:
config = yaml.load(f, Loader=yaml.Loader)[ticker]
client = discord.Client()
async def send_update(price, change24Hour, abbreviation):
status = f'{change24Hour}'
nickname = f'{abbreviation} ${price}'
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=status))
print(f"Updated name {nickname}")
print(f"Update status {status}")
print(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
guilds = await client.fetch_guilds(limit=150).flatten()
print("--------Guilds start here--------")
for guild in guilds:
await client.get_guild(guild.id).me.edit(nick=nickname)
await asyncio.sleep(0.5)
print("Updated: " + str(guild.id))
print("---------Guilds end here---------")
print("\n")
del guilds, status, nickname
await asyncio.sleep(config['updateFreq'])
@client.event
async def on_ready():
print("test")
while True:
getData = get_price(ticker)
price = str(getData[ticker]['usd'])
price = scientificToFloat(price)
change24Hour = str(getData[ticker]['usd_24h_change'])
change24Hour = "24h: " + str(percentStrip(change24Hour)) + "%"
await send_update(price, change24Hour, config['abbreviation'])
del getData, price, change24Hour
print(str(config['discordBotKey']))
client.run(str(config['discordBotKey']))
解决方案
推荐阅读
- python - 从谷歌驱动器下载后文件不显示
- r - R - 基于共享相似列但长度不同的另一个 data.frame 将列添加到第一个 data.frame
- c# - 使用 Entity Framework Core 2.0 更改或重命名列名而不丢失数据
- java - 如何避免swagger codegen接口中的默认方法实现?
- vba - 禁止“下载文件”框
- javascript - 根据 v-select 选项更改 v-slider 和 v-text-field 中显示的值
- html - 如何在打开时仅在模式弹出窗口内限制 Tab 键按下?
- angular - 使用 Angular 6 在嵌套组件中访问 RouterLinkActive
- java - 在 springboot 1.5->2.0 迁移期间 Postgresql 枚举中断
- eclipse - HTTP 状态 405 - 方法不允许(仅适用于使用 tomcat 服务器的球衣中的 DELETE 方法)