【发布时间】: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