Discord.py + 酒瓶

Discord.py + Bottlepy

我想 运行 一个带有 Discord.py 脚本的 Bottlepy 脚本,但只启动了 Bottlepy 脚本。

这是我的来源:

import asyncio
import bottle
import discord
from discord.ext import commands

client=commands.Bot(command_prefix=[">", "<", ".", "?", "!"])

#here where my script (not spectacular)

client.run("xxxxxXXXXxxXXetXxXXfXXxXXxXXXXxXxxxXxXX")
bottle.run(host='0.0.0.0', port=80)

要 运行 一个 Discord 机器人,请使用

client.run('token')

(如果您想了解 client.start() 的作用:here

现在会发生什么,只有你的 discord 机器人会 运行 而 bottle 脚本永远不会被调用。对于 运行 它们并行,我建议查看 threading

Client.start 是协程。您需要使用事件循环来 运行 它。

瓶子永远不会 运行 因为 client.run 正在阻塞。所以你需要运行在不同的线程中装瓶。

考虑一下

bot.run(TOKEN)
print("foobar") # this line will not run until the bot process ends.

因此,其中一个进程需要在备用线程中取消