多个用户的多线程Discord bot
我有一个需要帮助的问题。我创建了一个机器人,该机器人从Discord用户中获取输入并运行它以分析一些计算。这些计算通常需要40-50秒,并作为不和谐的答复返回结果。到目前为止,一切都很好。
但是,当其他用户或同一用户在进行中的其他单词(计算)时,在不和谐中键入另一个单词时,直到上一个完成后,新的单词才开始计算。我希望在上一个正在进行的过程中开始新的。我该如何编辑以使其正确?照亮我。谢谢。
import discord
from threading import Thread
import asyncio
client = discord.Client()
async def init():
loop = asyncio.get_event_loop()
loop.create_task(client.start('TOKEN'))
await Thread(target=loop.run_forever).start()
@client.event
async def on_ready():
print("we've logged in as {0.user}".format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!'):
try:
#calculation codes
await message.reply("calculation results")
except:
await message.reply("bla bla bla")
I have a issue that I need help. I created a bot that takes input from Discord Users and runs it to analyze for some calculations. These calculations takes 40-50 seconds usually and return the result as a reply in Discord. So far everything is fine.
But when other users or same user types another words in Discord while the previous one is in progress (calculation), the new one doesn't start to get calculated until the previous one gets done. I want the new one starts while the previous one is in progress. How can I edit this to make it right? Illuminate me. Thanks.
import discord
from threading import Thread
import asyncio
client = discord.Client()
async def init():
loop = asyncio.get_event_loop()
loop.create_task(client.start('TOKEN'))
await Thread(target=loop.run_forever).start()
@client.event
async def on_ready():
print("we've logged in as {0.user}".format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!'):
try:
#calculation codes
await message.reply("calculation results")
except:
await message.reply("bla bla bla")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论