因此,它的作用是,每当有人在聊天室频道中键入命令时!test
,它就会将以下适当的字符串打印到聊天频道中。但是,我希望命令一次只使用一次,所以我想锁定命令直到它完成:
import discord, asyncio, time
client = discord.Client()
@client.event
async def on_message(message):
lock = Lock() # define Lock
if message.content.lower().startswith("!test") and not lock.locked():
lock.acquire() # Lock the !test command so it can't be used now
await client.send_message(message.channel,'test1rgews')
await asyncio.sleep(1)
await client.send_message(message.channel,'test2thewf')
await asyncio.sleep(1)
await client.send_message(message.channel,'test3rhtvw')
await asyncio.sleep(1)
await client.send_message(message.channel,'test4trjyr')
await asyncio.sleep(1)
await client.send_message(message.channel,'test5dmuye')
await asyncio.sleep(10)
lock.release() # Unlock the !test command now
client.run('clienttokenhere')
但是我收到一个错误NameError: name 'Lock' is not defined
,即使我确实将其定义为lock = Lock()
.