TwitchIO бот без блокировкиPython

Программы на Python
Ответить
Anonymous
 TwitchIO бот без блокировки

Сообщение Anonymous »

Я хотел бы использовать TwitchIO для общения с чатом Twitch внутри другой программы без необходимости перехватывать основной цикл с помощью функции run() бота.
Официальная документация здесь (https: //twitchio.readthedocs.io/en/latest/quickstart.html) показывает выполняемый код следующим образом:

Код: Выделить всё

from twitchio.ext import commands

class Bot(commands.Bot):

def __init__(self):
# Initialise our Bot with our access token, prefix and a list of channels to join on boot...
# prefix can be a callable, which returns a list of strings or a string...
# initial_channels can also be a callable which returns a list of strings...
super().__init__(token='ACCESS_TOKEN', prefix='?', initial_channels=['...'])

async def event_ready(self):
# Notify us when everything is ready!
# We are logged in and ready to chat and use commands...
print(f'Logged in as | {self.nick}')

@commands.command()
async def hello(self, ctx: commands.Context):
# Here we have a command hello, we can invoke our command with our prefix and command name
# e.g ?hello
# We can also give our commands aliases (different names) to invoke with.

# Send a hello back!
# Sending a reply back to the channel is easy... Below is an example.
await ctx.send(f'Hello {ctx.author.name}!')

bot = Bot()
bot.run()
# bot.run() is blocking and will stop execution of any below code here until stopped or closed.
Но, как сказано в последней строке, run() заблокирует выполнение.
Есть ли какой-нибудь другой способ его запуска, который не блокирует? Что-то вроде (выдумано)

Код: Выделить всё

bot.poll()
Это нужно будет периодически запускать в основном цикле моей программы?

Подробнее здесь: https://stackoverflow.com/questions/701 ... t-blocking
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»