Rename Assets when it is uploaded I would like to rename new assets by PHP, but somehow it does not work.
In Craft 3, I suppose it is like;

Event::on(\craft\services\Elements::class, \craft\services\Elements::EVENT_AFTER_SAVE_ELEMENT, function(Event $event) {
    if ($event-&gt;params['isNewAsset']) {
        $asset = $event-&gt;params['asset'];
        $folder_id = $asset-&gt;folderId;

        if ($folder_id == "22")
        {
            $filename = $asset-&gt;filename . "_test";
            craft()-&gt;assets-&gt;renameFile($asset, $filename);
        }
    }
});


My code is like that, but this message appears;

Upload failed. The error message was: “Getting unknown property: craft\events\ElementEvent::params


Could you help me?
You are mixing Craft 2 methods with Craft 3 methods.
This will get the the assets extension with $asset-&gt;getFilename(true) and add test_ in the beginning of the filename:

Event::on(
    \craft\services\Elements::class,
    \craft\services\Elements::EVENT_AFTER_SAVE_ELEMENT,
    function(Event $event)   {
        $asset = $event-&gt;element;
        $folderId = $asset-&gt;getFolder();


        if ($event-&gt;isNew &amp;&amp; $asset instanceof craft\elements\Asset &amp;&amp; $folderId == '22') {
            $newName =  'test_' . $asset-&gt;getFilename(true);
            Craft::$app-&gt;assets-&gt;moveAsset($asset, $folderId, $newName);
        }
    }
);