【问题标题】:I want to use asycnio in python to print something while taking inputs [closed]我想在 python 中使用 asyncio 在输入时打印一些东西[关闭]
【发布时间】:2021-10-04 13:47:06
【问题描述】:

我正在使用 python 进行聊天。我正在使用不和谐并从那里获取输入。我希望用户始终处于发送模式,但也能够随时阅读消息。

from discord.ext import commands
import asyncio

bot = commands.Bot("!")

username = input("your display name: ")
@bot.event
async def on_ready():
    print('successfully logged in as {}'.format(username))

@bot.command()
async def message(ctx, author, receiver, context):
    if (receiver == username):
        print("{}: {}".format(author, context))
        #i want this to be printed while taking input

#and i cant take input using normal input()

bot.run("my token")

我对python只有基本的了解,所以请不要评判我。

【问题讨论】:

  • 1. input() 正在阻塞代码,并且在 asynio 中不会同时运行任何东西; 2. 在事件循环开始之前运行的所有东西(bot.run())也不会与异步代码同时运行。

标签: python discord chat python-asyncio


【解决方案1】:

我现在明白这是不可能的了,谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 2021-12-05
    • 2014-02-17
    • 1970-01-01
    • 2016-06-29
    • 2018-06-28
    相关资源
    最近更新 更多