Discord.py silence command

冷暖自知 提交于 2019-11-29 15:20:13

Something like

silent_channels = set()

@BSL.event
async 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)

Should work (I haven't tested it, testing bots is a pain). Searching through sets is fast, so doing it for every message shouldn't be a real burden on your resources.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!