python-3.x discord机器人不添加冷却到命令

cx6n0qe3  于 2023-01-03  发布在  Python
关注(0)|答案(1)|浏览(141)

我为我和我的朋友们做了一个机器人,这是它的功能之一,它在vc中静音和耳聋的人为5秒,并增加了一个冷却到命令为1小时,但它没有增加冷却任何帮助

# Check if the message is a command
if message.content.startswith('!spin'):
    # Get the command and arguments from the message
    command, *args = message.content.split()
    command = command[1:]  # remove the leading exclamation mark

    # Check if the command is on cooldown
    if command in cooldowns and cooldowns[command] > message.created_at:
        # The command is on cooldown, so do not execute it
        return

    # Check which command was used
    if command == 'spin':
        # Scan the voice channels in the server
        for channel in message.guild.voice_channels:
            # Get the members in the voice channel
            members = channel.members
            if not members:
                return

            # Pick a random member from the list of members
            lucky_member = random.choice(members)
            # Mute and deafen the lucky member for 5 seconds
            await lucky_member.edit(mute=True, deafen=True)
            await asyncio.sleep(5)  # delay for 5 seconds
            await lucky_member.edit(mute=False, deafen=False)
            await message.channel.send('command is on cooldown for 1h')

        # Put the command on cooldown for 1 hour
        cooldowns[command] = message.created_at + datetime.timedelta(hours=1)
a64a0gku

a64a0gku1#

我发现了问题所在:

cooldowns[command] = message.created_at + datetime.timedelta(hours=1)

我需要被标记一次,这样它就在正确的位置上的代码工作

相关问题