就像是
silent_channels = set()@BSL.eventasync def on_message(message): if message.channel in silent_channels: if not message.author.server_permissions.administrator and message.author.id != ownerID: await BSL.delete_message(message) return await BSL.process_commands(message)@BSL.command(pass_context=True)async def silent(ctx, length=0): # Corrected spelling of length if ctx.message.author.server_permissions.administrator or ctx.message.author.id == ownerID: silent_channels.add(ctx.message.channel) await BSL.say('Going silent.') if length: length = int(length) await asyncio.sleep(length) if ctx.message.channel not in silent_channels: # Woken manually return silent_channels.discard(ctx.message.channel) await BSL.say('Waking up.')@BSL.command(pass_context=True)async def wake(ctx): silent_channels.discard(ctx.message.channel)
应该可以工作(我还没有测试过,测试机器人很痛苦)。在集合中快速搜索,因此对每条消息进行搜索都不会真正给您的资源带来负担。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)