Python discord.py script runs in terminal/windows but not python_scripts (via shell_command)

I am using a script that I wrote in python for server muting a user via discord.py
I wrote it initially on my desktop and checked it worked (no issues), then put it in my python_scripts folder and ran it via terminal (no issues).
Finally, I then added a shell_command to run it from an automation and when I do, I get the following response:

stdout: None
stderr: |-
  Traceback (most recent call last):
    File "/config/python_scripts/discord_server_mute.py", line 11, in <module>
      intents = discord.Intents.default()
                ^^^^^^^^^^^^^^^
  AttributeError: module 'discord' has no attribute 'Intents'
returncode: 1

Conguration.yaml extract:

shell_command:
  discord_mute: 'python3 /config/python_scripts/discord_server_mute.py {{ user_id }}'

Python script (/homeassistant/python_scripts/discord_server_mute.py):

import discord
from discord.ext import commands
import sys

# Replace these with your actual bot token and your user ID
TOKEN = 'REMOVED'
GUILD_ID = REMOVED

print(discord.__file__)

intents = discord.Intents.default()
intents.members = True 

client = commands.Bot(command_prefix='!', intents=intents)

async def mute_user(user_id):
    guild = discord.utils.get(client.guilds, id=GUILD_ID)
    if guild:
        member = discord.utils.get(guild.members, id=user_id)
        if member:
            await member.edit(mute=True)
            print(f'Muted {member.name}')
        else:
            print('User not found in the guild')
    else:
        print('Guild not found')

@client.event
async def on_ready():
    user_id = int(sys.argv[1])
    await mute_user(user_id)
    await client.close()

client.run(TOKEN)

N.B. - discord.py is not advised for use by discord itself so do not use this code without knowledge of the topic please as it is your risk to take.

I have tried to double and triple check that there are no conflicts in the discord module but any help / ideas would be appreciated even if basic - I am not very experienced in python or home assistant console commands.

Thank you in advance.

You can find the list of modules installed inside the HA container at:

Running a script via the terminal is no guarantee it will run inside HA as they are 2 completely different containers.
HA is using nextcord 2.6.0. Please test your script in a similar environment to confirm it is actually working with HA.

About 2y ago I tested something similar (not discord but libs). I believe that pyscript allows to use a file ‘requirements.txt’ where you can add additional libs to load in HA env. At the time this was working for my then-example but I donot have that env anymore…just my 2cts